Repository navigation
DataViews: use Menu from @wordpress/ui
#81783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a5061cd
DataViews: Use @wordpress/ui Menu in the add-filter menu
oandregal 8f41717
DataViews: Use @wordpress/ui Menu for item actions
oandregal 7620236
DataViews: Use @wordpress/ui Menu in the column header menu
oandregal e5c4217
DataViews: Use @wordpress/ui Menu in the layout switcher
oandregal 9b4c929
DataViews: Add changelog entry for the Menu migration
oandregal aa5dd56
Remove unnecessary MenuGroup
oandregal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,6 @@ | ||
| import clsx from 'clsx'; | ||
| import { useInstanceId, usePrevious } from '@wordpress/compose'; | ||
| import { | ||
| Button, | ||
| privateApis as componentsPrivateApis, | ||
| Spinner, | ||
| Composite, | ||
| } from '@wordpress/components'; | ||
| import { Button, Spinner, Composite } from '@wordpress/components'; | ||
| import { | ||
| useCallback, | ||
| useEffect, | ||
|
|
@@ -17,8 +12,8 @@ import { | |
| import { __, sprintf } from '@wordpress/i18n'; | ||
| import { moreVertical } from '@wordpress/icons'; | ||
| import { useRegistry } from '@wordpress/data'; | ||
| import { Stack, VisuallyHidden } from '@wordpress/ui'; | ||
| import { unlock } from '../../../lock-unlock'; | ||
| // eslint-disable-next-line @wordpress/use-recommended-components -- Intentional early adoption of the new Menu, pending WordPress/gutenberg#76135. | ||
| import { Menu, Stack, VisuallyHidden } from '@wordpress/ui'; | ||
| import { ActionsMenuGroup, ActionModal } from '../../dataviews-item-actions'; | ||
| import DataViewsContext from '../../dataviews-context'; | ||
| import { useDelayedLoading } from '../../../hooks/use-delayed-loading'; | ||
|
|
@@ -48,8 +43,6 @@ interface ListViewItemProps< Item > { | |
| posinset?: number; | ||
| } | ||
|
|
||
| const { Menu } = unlock( componentsPrivateApis ); | ||
|
|
||
| function generateItemWrapperCompositeId( idPrefix: string ) { | ||
| return `${ idPrefix }-item-wrapper`; | ||
| } | ||
|
|
@@ -226,37 +219,44 @@ function ListItem< Item >( { | |
| ) } | ||
| { ! hasOnlyOnePrimaryAction && ( | ||
| <div role="gridcell"> | ||
| <Menu placement="bottom-end"> | ||
| <Menu.TriggerButton | ||
| { /* The `disabled` prop on `Menu.Root` (rather than on | ||
| the trigger) keeps the menu from opening while | ||
| letting the trigger button stay focusable via its | ||
| own `accessibleWhenDisabled`. */ } | ||
| <Menu.Root disabled={ ! actions.length }> | ||
| <Menu.Trigger | ||
| render={ | ||
| <Composite.Item | ||
| id={ generateDropdownTriggerCompositeId( | ||
| idPrefix | ||
| ) } | ||
| accessibleWhenDisabled | ||
| render={ | ||
| <Button | ||
| size="small" | ||
| icon={ moreVertical } | ||
| label={ __( 'Actions' ) } | ||
| accessibleWhenDisabled | ||
| disabled={ ! actions.length } | ||
| onKeyDown={ | ||
| onKeyDownCapture={ | ||
| onDropdownTriggerKeyDown | ||
| } | ||
| /> | ||
| } | ||
| /> | ||
| } | ||
| /> | ||
| <Menu.Popover> | ||
| <Menu.Popup | ||
| positioner={ <Menu.Positioner align="end" /> } | ||
| > | ||
| <ActionsMenuGroup | ||
| actions={ eligibleActions } | ||
| item={ item } | ||
| registry={ registry } | ||
| setActiveModalAction={ setActiveModalAction } | ||
| /> | ||
| </Menu.Popover> | ||
| </Menu> | ||
| </Menu.Popup> | ||
| </Menu.Root> | ||
| { !! activeModalAction && ( | ||
| <ActionModal | ||
| action={ activeModalAction } | ||
|
|
@@ -503,13 +503,15 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) { | |
| }, [ isActiveIdInList, selectCompositeItem, previousActiveItemIndex ] ); | ||
|
|
||
| // Prevent the default behavior (open dropdown menu) and instead select the | ||
| // dropdown menu trigger on the previous/next row. | ||
| // https://github.com/ariakit/ariakit/issues/3768 | ||
| // dropdown menu trigger on the previous/next row. Runs in the capture | ||
| // phase and stops propagation because the menu's open-on-arrow-key | ||
| // behavior doesn't check whether the event's default was prevented. | ||
| const onDropdownTriggerKeyDown = useCallback( | ||
| ( event: React.KeyboardEvent< HTMLButtonElement > ) => { | ||
| if ( event.key === 'ArrowDown' ) { | ||
| // Select the dropdown menu trigger item in the next row. | ||
| event.preventDefault(); | ||
| event.stopPropagation(); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This highlights one difference between AriaKit and BaseUI. AriaKit checked if the default event was canceled (example): if so, it would not trigger its own. But BaseUI does not do this, hence the need for |
||
| selectCompositeItem( | ||
| activeItemIndex + 1, | ||
| generateDropdownTriggerCompositeId | ||
|
|
@@ -518,6 +520,7 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) { | |
| if ( event.key === 'ArrowUp' ) { | ||
| // Select the dropdown menu trigger item in the previous row. | ||
| event.preventDefault(); | ||
| event.stopPropagation(); | ||
| selectCompositeItem( | ||
| activeItemIndex - 1, | ||
| generateDropdownTriggerCompositeId | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the differences from the existing component is that the new one doesn't track how many items does it have to handle disability. This is so this works (note how the "Add filter" remains focusable when there's no more filters to add):
Screen.Recording.2026-08-18.at.13.15.50.mov