Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/dataviews/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
### Internal

- Update `@ariakit/react` to 0.4.37 ([#81080](https://github.com/WordPress/gutenberg/pull/81080)).
- DataViews: Replace the private `Menu` from `@wordpress/components` with the `Menu` from `@wordpress/ui` in the item actions, list layout, column header, add-filter, and layout switcher menus. ([#81783](https://github.com/WordPress/gutenberg/pull/81783))
- Point tsconfig references at split dependencies' build projects. ([#81509](https://github.com/WordPress/gutenberg/pull/81509), [#81514](https://github.com/WordPress/gutenberg/pull/81514), [#81516](https://github.com/WordPress/gutenberg/pull/81516))
- Split tsconfig into a build project and a default dev project so dev files are type checked without publishing their declarations. ([#81515](https://github.com/WordPress/gutenberg/pull/81515))
- DataForm: Narrow the combobox control's `onChange` handler parameter back to `string | null`, following the upstream `ComboboxControl` type fix that removed the accidental `undefined` from the callback type. [#81568](https://github.com/WordPress/gutenberg/pull/81568)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import type { Ref } from 'react';
import {
privateApis as componentsPrivateApis,
Button,
} from '@wordpress/components';
import { Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { forwardRef } from '@wordpress/element';
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 } from '@wordpress/ui';
import type { NormalizedFilter, View } from '../../types';

const { Menu } = unlock( componentsPrivateApis );

interface AddFilterProps {
filters: NormalizedFilter[];
view: View;
Expand All @@ -24,13 +20,16 @@ export function AddFilterMenu( {
setOpenedFilter,
triggerProps,
}: AddFilterProps & {
triggerProps: React.ComponentProps< typeof Menu.TriggerButton >;
triggerProps: React.ComponentProps< typeof Menu.Trigger >;
} ) {
const inactiveFilters = filters.filter( ( filter ) => ! filter.isVisible );
return (
<Menu>
<Menu.TriggerButton { ...triggerProps } />
<Menu.Popover>
// 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={ ! inactiveFilters.length }>

Copy link
Copy Markdown
Member Author

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

<Menu.Trigger { ...triggerProps } />
<Menu.Popup>
{ inactiveFilters.map( ( filter ) => {
return (
<Menu.Item
Expand All @@ -55,8 +54,8 @@ export function AddFilterMenu( {
</Menu.Item>
);
} ) }
</Menu.Popover>
</Menu>
</Menu.Popup>
</Menu.Root>
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import type { MouseEventHandler } from 'react';
import {
Button,
Modal,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { Button, Modal } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useMemo, useState } from '@wordpress/element';
import { moreVertical } from '@wordpress/icons';
import { useRegistry } from '@wordpress/data';
import { useViewportMatch } from '@wordpress/compose';
import { Stack } from '@wordpress/ui';
// eslint-disable-next-line @wordpress/use-recommended-components -- Intentional early adoption of the new Menu, pending WordPress/gutenberg#76135.
import { Menu, Stack } from '@wordpress/ui';
import { kebabCase } from '@wordpress/kebab-case';
import { unlock } from '../../lock-unlock';
import type { Action, ActionModal as ActionModalType } from '../../types';

const { Menu } = unlock( componentsPrivateApis );

export interface ActionTriggerProps< Item > {
action: Action< Item >;
onClick: MouseEventHandler;
Expand Down Expand Up @@ -240,8 +234,11 @@ function CompactItemActions< Item >( {
);
return (
<>
<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={
<Button
size={ isSmall ? 'small' : 'compact' }
Expand All @@ -253,15 +250,15 @@ function CompactItemActions< Item >( {
/>
}
/>
<Menu.Popover>
<Menu.Popup positioner={ <Menu.Positioner align="end" /> }>
<ActionsMenuGroup
actions={ actions }
item={ item }
registry={ registry }
setActiveModalAction={ setActiveModalAction }
/>
</Menu.Popover>
</Menu>
</Menu.Popup>
</Menu.Root>
{ !! activeModalAction && (
<ActionModal
action={ activeModalAction }
Expand Down
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,
Expand All @@ -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';
Expand Down Expand Up @@ -48,8 +43,6 @@ interface ListViewItemProps< Item > {
posinset?: number;
}

const { Menu } = unlock( componentsPrivateApis );

function generateItemWrapperCompositeId( idPrefix: string ) {
return `${ idPrefix }-item-wrapper`;
}
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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 stopPropagation.

selectCompositeItem(
activeItemIndex + 1,
generateDropdownTriggerCompositeId
Expand All @@ -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
Expand Down
Loading
Loading