Repository navigation
Description
Context
As we're re-writing some of the components in the @wordpress/components package to use ariakit, we have the chance to re-discuss our approach to architecting our APIs and the behavior of such components.
More specifically, as we're working on the new version of DropdownMenu and CustomSelectControl, one of the aspects that we should discuss and agree on at a package level is the modality of popover-based components.
Using ariakit allows us to easily switch the modality (and related behaviour) of popover-based components (popover, tooltips, dropdowns, dropdown menus, dialogs, selects, comboboxes...) via a few props.
Note
Making a popover "modal" means that the rest of the page should be considered inert (inaccessible to assistive technology and non-interactable by the user while the popover is open, as explained well in this article).
In ariakit there are some related aspects that come with modality (and can be customized to a degree):
- by default, modal popovers are portal'ed and appended to the
document.body, while non-modal popovers are rendered inline - by default, modal popovers prevent scrolling on
document.body - in modal dialogs, the level of ariakit-provided headings is re-set so that they start at
h1 - a hidden "dismiss" button is rendered in modal popovers
What
Therefore, we need to decide:
- What should the default modality of popover-based components be? Should it be different depending on the component?
- Should we expose APIs in our components to change such modality? If yes, for what components and in what shape?
- Should make amends to the default ariakit behavior re. inline vs portaled popover depending on the modality?
- Should make amends to the default ariakit behavior re.preventing body scroll depending on the modality?
- Are we ok with the addition of a hidden dismiss button for modal popovers?
- Do we need to take any additional precautions into account, given that there will be a transional phase during which some components will use the ariakit popover, and other components will use the first-party
Popoverfrom this package?
cc @WordPress/gutenberg-components
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
ciampo commentedon Jul 17, 2024
I'll share my initial thoughts:
I'd opt for most components to be
modalby default, exceptTooltipWe should in most cases, apart from:
Tooltip, which should likely never be modalDialog(what today we mistakenly callModal) which we could argue could bemodal-onlyI personally like
ariakit's default behaviour, and I'd like to preserve it if possible. If rendering inline by default for non-modal popovers proves tricky, my second-best option would be to always portal them todocument.bodyby default, and expose dedicated APIs for consumers of the component to change such behavior as needed (render inline, or change portal element).Having said that, that's a topic with more nuances, and I decided to discuss it separately in #63697
I think that this behavior is sensible and I wouldn't change it. I would start without exposing dedicated props in our components, and see if we can get away with it.
I am.
We will need to keep an eye on a few aspects:
Interactions between popover-based components that use different underlying components
For example, a dropdown menu that opens a modal.
We should be able to get around such issues because our new components will expose enough APIs that we could mimic the legacy
Popoverbehavior if needed, and reach behavior parity.Ideally, when all popover-based components use
ariakit, we should be able to stop using the majority of these tweaks (slots, z-indexes, ...)Introducing more modality in the editor
As of today, most popover-based components are not
modal. So, making the modal by default would represent a bit of a change in how users interact with the component. We should keep an eye on that, and talk to product/design folks to get some early feedback.[-]Components: modality of popover-based components[/-][+]@wordpress/components: modality of popover-based components[/+][-]@wordpress/components: modality of popover-based components[/-][+]`@wordpress/components`: modality of popover-based components[/+]tyxla commentedon Jul 18, 2024
In general, I'm fine with introducing more modality in most of the popover-based components. That's how native controls work, and when playing with Storybook, I can see quite a few of our components that I expect to be modal, but they aren't. With that in mind, defaulting to modal makes sense to me.
That being said, let's get some early feedback from @WordPress/gutenberg-design to ensure we take any early thoughts into consideration when making direction decisions like this. Especially considering that there might be a longer transition period where some components will be modal while others won't be.
mirka commentedon Jul 19, 2024
I'm pretty much in line with @ciampo's takes.
I played around with this, and couldn't figure out how it becomes focusable. It's in the DOM but left out of the tab sequence with
tabindex="-1". It didn't work withAriakit.Dialogeither. I'm theoretically ok with this feature, but can't fully assess at the moment due to not being able to actually trigger it 😅ciampo commentedon Jul 22, 2024
Maybe @diegohaz can help
diegohaz commentedon Jul 22, 2024
@mirka @ciampo
The hidden dismiss button added by modal dialogs in Ariakit is designed for screen reader users when a mouse and keyboard are not available (e.g., on mobile/touch devices). They can't click outside or press Esc, but they can access this button.
Without this button, they wouldn't be able to close the modal dialog or popover.
It's rendered only if the developer does not deliberately render
DialogDismiss,PopoverDismiss, or another derivative component.mirka commentedon Jul 22, 2024
I confirmed the StackBlitz demo works as expected on iOS Safari with VoiceOver. Very cool feature, and completely non-intrusive to a user who doesn't need it. Thumbs up from me as well. Thanks @diegohaz!
joedolson commentedon Jul 23, 2024
Having a dismiss button is most helpful because it makes the action needed to dismiss visible and obvious to users who don't know other methods of exiting, such as
escor off-control cilcks.I'm opposed to adding a visually hidden dismiss; I think it needs to be visible and always available. Current popover controls have a visible dismiss button, and I'd consider removing that to be a significant accessibility regression; and I don't see any point in adding a visually hidden dismiss button when we have a visible one already.
I think our usage of this component should default to including the appropriate DialogDismiss or PopoverDismiss component, but I'm glad that there is at least some fallback if a developer omits those.
I'd prefer if it was also available via normal keyboard & screen reader navigation; I'm not sure why it's restricted to mobile interfaces only. @diegohaz can you provide any explanation of that?
diegohaz commentedon Jul 23, 2024
It's not restricted to mobile devices. It's accessible to the virtual cursor on any device or screen reader. Making it accessible to non-screen reader keyboard navigation would require Ariakit to make this button visible, which involves design decisions beyond the library's scope.
I agree that always rendering a visible dismiss button is better, and
@wordpress/componentscan do that. My comment was only to explain what Ariakit does within its limited scope.ciampo commentedon Jul 24, 2024
Hey @joedolson, I believe that a visible dismiss button is only present in the
Modalcomponent.Here we're discussing modality as a general attribute for all popover-based components. I believe that it would be quite difficult to show a visible dismiss button for all modal popover - based components, and instead we should evaluate the addition of a visual dismiss button on a case by case.
For example:
13 remaining items
alexstine commentedon Aug 16, 2024
@diegohaz I am using NVDA and Firefox. If I switch to the virtual cursor (browse mode) pressing up arrow lands on the aria-live region injected by wordpress/a11y. By default, most of the portals I've seen in Gutenberg render near the end of the DOM, not as siblings/descendants of their controls.
diegohaz commentedon Aug 16, 2024
@alexstine I can test it again later. The last time I tested it with NVDA and Firefox, it worked properly. The portal is rendered at the end of the document in the DOM, but it's referenced by
aria-ownson a sibling element of the original control that triggered the popover. Therefore, the accessibility tree should be structured as if there were no portal.diegohaz commentedon Aug 16, 2024
Here's an audio/video I recorded using NVDA 2024.2 and Firefox 129.0.1 on Windows 11, following the instructions in #64200
In the first part of the video, I use Tab and Shift + Tab to navigate from the menu button to the menu, to the table (the element after the menu button), and back to the menu and the menu button. Then, I use arrow up and arrow down in browse mode to navigate from the menu button to the menu items and back to the menu button.
The order of elements in both scenarios seems correct even though the menu is using React Portal to be rendered at the end of the DOM.
Parallels.Desktop.mp4
afercia commentedon Sep 6, 2024
Some feedback on a few points from this discussion.
@ciampo, sure and that also means that Popovers must have a role depending on how they are used. When they're used for dialog-like UIs, they should have a role dialog, when they're used for menu-like UIs they whould have a role menu and so on. As such, the Popover component should have a required prop to set an appropriate role and it should not allow implementations without a role.
I agree and that was discussed several times across the yers iin this project. Alas, some designs don't want a dismiss button ad right now there's larte inconsistency in the editor. One exampel of that is in the varous 'welcome' modal dialogs. To me, a dismiss button should be required.
Yes, but the modality also implies that the Popover must have an appropriate ARIA role. I'd like to remind everyone that the concept of 'modality' and thus the aria-modal attirbute can only be used with the
dialogandalertdialogroles.What would be the use case for a dropdown menu that is modal? I'm not sure I've ever seen a menu that makes inert the rest of the page other than in Gutenberg and to me that's an incorrect pattern. Glad it will be revised as mentioned by @tyxla.
Regarding required ARIA roles and attributes, I'd argue that if the components don't make them requried, it is very likely the components will be used incorrectly. This is no different from other long-standing issues like the non-required
labelprop for inputs and buttons, which made a lot of harms across the 7 years of life of this project. I do realize components should be 'flexible' but they also should be 'strict' in requiring the necessary props to guarantee correct semantics and highest level of usability and accessibility.Agreed and appreciated. We all want that, not only you as maintainers 🙂
This is a good point from @alexstine. Ideally, any UI that renders in the DOM far from the toggle control that opened it should be treated like a modal dialog. As Alex explains, assistive technologies provide dozens of ways to exit an UI even if tabbing is constrained within that UI. When that happens, users would be totally lost because there's a lot of content in the DOM between the Popover and the toggle that opened it. Which leads us to discuss the 'portal' pattern. It should really be used only for UIs that are modal as in UIs that make all the rest of the page inert.
Also the above point has been discussed several times across the years in this project but always dismissed for a reason or another reason. I would like to reinstate once again that for accessibility:
tyxla commentedon Sep 6, 2024
@afercia: note that I never said we're necessarily going in that direction. In my comment, I was explaining how the PR works, but as specified in the PR, it was solely for demonstration purposes and getting feedback. The whole idea was to test different ways to set things up and see how we can achieve the best compromise.
afercia commentedon Sep 9, 2024
@tyxla Sure, thanks for the clarification 👍🏻
stokesman commentedon Sep 16, 2024
Speaking only in the context of mouse/pointer use, it’s nice for dismissing the menu with a hasty click outside because there’s no risk of triggering another action inadvertently. Another way to state it is that for non-modal dropdowns, too much care is often required to avoid some other clickable element when merely intending to dismiss the popover.
A tradeoff is that if you want to open another element directly then the first click won’t do it. This is conceivably avoidable though with some technical challenge for the web. An example is Mac OS dropdown menus which are modal in respect to the rest of the interface but adjacent menus open when moving the pointer over their toggles. Such an affordance would be nice at least for some contexts in Gutenberg but as mentioned it may not be easily added.
Overall, my intuition is that affording the "safer" pointer dismissal is worth the tradeoff of another click required to activate the next button/link. However, the change may be noticed by and cause annoyance to some so I don’t feel too strongly about it.
Debate of which is best aside, it seems more sane to have dropdowns behave consistently so, until all dropdowns could be made modal at once, there shouldn’t be any dropdowns that are modal. I.e. #64200 seems the right thing to do for now.
afercia commentedon Sep 17, 2024
Interesting, I didn't know they were modal thanks for pointing that out.
In my mind, in a web interface (which isn't directly comparable to an operating system interface), an UI that is modal should also visually communicate that interaction with the rest of the page is prevented. The visual indication of the modality is a key part of a modal UI.
Typically, this is done with an overlay with some opacity. As an added bonus, the overlay prevents clicking on any part of the rest of the UI. From a visual perspective, the overlay is a pretty common pattern for modal dialogs. I'm not sure it would be good for a dropdown menu though or any other modal UI that isn't a dialog.
ciampo commentedon Sep 17, 2024
Out of curiosity, what about native
<select />elements? They seem to believe in a modal way, but without an overlay. Clicking outside of the popover would hide it, but another click would be necessary to interact with the rest of the UI. Focus is constrained in the list popover, and I believe the rest of the document is intert too?Hence why I was considering making components like
SelectControl,CustomSelectControl,DropdownMenu(and potentiallyComboboxControlandFormTokenField) default-modal too, but without necessarily showing a semi-opaque overlay on top of the rest of the document.Having said that, by exposing the right props (ie.
modal,hideOnEscape,hideOnInteractOutside,preventBodyScroll, as on ariakit's Popover), consumers of the components would be able to tweak such behavior as needed.afercia commentedon Sep 17, 2024
Modality is not just about visuals and keyboard interaction. The key parts are that when a modal UI opens, the rest of the page:
To use the example of the Mac OS dropdown menus provided by @stokesman, when I open one of the menus in the macOS toolbar VoiceOver doesn't perceive any other content in the page. The same thing happens with native select elements. I don't know whether that happens also on Windows. Anyways, I see that as an operating system pattern as also native select element are highly dependent on the operating system.
Instead, I would like to remind everyone that the aria-modal attribute can only be used on UIs with a role of window, dialog, or alertdialog. Which hints that a modal behavior can be used only on those patterns. An entirely different matter is constraining tabbing or implementing only some parts of a modal behavior on other kind of UIs.
ciampo commentedon Sep 17, 2024
Yup, I'm aware of how inertness and modality are related (I also linked to this article in this issue's first message).
What I'm trying to say is: if the native
selectelement is modal, why shouldn't our equivalent component be modal too by default? It would make sense to me to offer an experience as close as possible to the native counterpart. (The same reasoning would apply for dropdown menus, etc.).Are you saying that modality of native components varies from OS to OS, and therefore we can't assume that all native
selectimplementations are modal?afercia commentedon Sep 18, 2024
Honestly I don't know. It should be tested. But I don't think it's worth it. As I mentioned earlier, the
aria-modalattribute is only allowed on window, dialog, and alertdialog which means that for web interfaces the moda behavior is only expected for those roles. Assistive technologies are built on top of the specifications so they would expect a modal behavior only on those roles as well.ciampo commentedon Sep 3, 2026
Closing as the new overlay components in the
@wordpress/uiexpose amodalprop that allows consumers to easily tweak their modality.