Skip to content
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

DropdownMenuV2: rename to Menu #66289

Merged
merged 7 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
28 changes: 14 additions & 14 deletions packages/block-editor/src/hooks/block-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { useBlockEditContext } from '../components/block-edit';
import { useBlockBindingsUtils } from '../utils/block-bindings';
import { store as blockEditorStore } from '../store';

const { DropdownMenuV2 } = unlock( componentsPrivateApis );
const { Menu } = unlock( componentsPrivateApis );

const EMPTY_OBJECT = {};

Expand Down Expand Up @@ -70,18 +70,18 @@ function BlockBindingsPanelDropdown( { fieldsList, attribute, binding } ) {
<>
{ Object.entries( fieldsList ).map( ( [ name, fields ], i ) => (
<Fragment key={ name }>
<DropdownMenuV2.Group>
<Menu.Group>
{ Object.keys( fieldsList ).length > 1 && (
<DropdownMenuV2.GroupLabel>
<Menu.GroupLabel>
{ registeredSources[ name ].label }
</DropdownMenuV2.GroupLabel>
</Menu.GroupLabel>
) }
{ Object.entries( fields )
.filter(
( [ , args ] ) => args?.type === attributeType
)
.map( ( [ key, args ] ) => (
<DropdownMenuV2.RadioItem
<Menu.RadioItem
key={ key }
onChange={ () =>
updateBlockBindings( {
Expand All @@ -95,17 +95,17 @@ function BlockBindingsPanelDropdown( { fieldsList, attribute, binding } ) {
value={ key }
checked={ key === currentKey }
>
<DropdownMenuV2.ItemLabel>
<Menu.ItemLabel>
{ args?.label }
</DropdownMenuV2.ItemLabel>
<DropdownMenuV2.ItemHelpText>
</Menu.ItemLabel>
<Menu.ItemHelpText>
{ args?.value }
</DropdownMenuV2.ItemHelpText>
</DropdownMenuV2.RadioItem>
</Menu.ItemHelpText>
</Menu.RadioItem>
) ) }
</DropdownMenuV2.Group>
</Menu.Group>
{ i !== Object.keys( fieldsList ).length - 1 && (
<DropdownMenuV2.Separator />
<Menu.Separator />
) }
</Fragment>
) ) }
Expand Down Expand Up @@ -175,7 +175,7 @@ function EditableBlockBindingsPanelItems( {
} );
} }
>
<DropdownMenuV2
<Menu
placement={
isMobile ? 'bottom-start' : 'left-start'
}
Expand All @@ -195,7 +195,7 @@ function EditableBlockBindingsPanelItems( {
attribute={ attribute }
binding={ binding }
/>
</DropdownMenuV2>
</Menu>
</ToolsPanelItem>
);
} ) }
Expand Down
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- `Tabs`: update indicator more reactively ([#66207](https://github.com/WordPress/gutenberg/pull/66207)).
- `Tabs` and `TabPanel`: Fix arrow key navigation in RTL ([#66201](https://github.com/WordPress/gutenberg/pull/66201)).
- `Tabs`: override tablist's tabindex only when necessary ([#66209](https://github.com/WordPress/gutenberg/pull/66209)).
- `DropdownMenuV2`: rename to `Menu` ([#66289](https://github.com/WordPress/gutenberg/pull/66289)).

### Internal

Expand Down
44 changes: 22 additions & 22 deletions packages/components/src/menu/README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
# `DropdownMenuV2`
# `Menu`

<div class="callout callout-alert">
This feature is still experimental. “Experimental” means this is an early implementation subject to drastic and breaking changes.
</div>

`DropdownMenuV2` displays a menu to the user (such as a set of actions or functions) triggered by a button.
`Menu` displays a menu to the user (such as a set of actions or functions) triggered by a button.

## Design guidelines

### Usage

#### When to use a DropdownMenu
#### When to use a `Menu`

Use a DropdownMenu when you want users to:
Use a `Menu` when you want users to:

- Choose an action or change a setting from a list, AND
- Only see the available choices contextually.

`DropdownMenu` is a React component to render an expandable menu of buttons. It is similar in purpose to a `<select>` element, with the distinction that it does not maintain a value. Instead, each option behaves as an action button.
`Menu` is a React component to render an expandable menu of buttons. It is similar in purpose to a `<select>` element, with the distinction that it does not maintain a value. Instead, each option behaves as an action button.

If you need to display all the available options at all times, consider using a Toolbar instead. Use a `DropdownMenu` to display a list of actions after the user interacts with a button.
If you need to display all the available options at all times, consider using a Toolbar instead. Use a `Menu` to display a list of actions after the user interacts with a button.

**Do**
Use a `DropdownMenu` to display a list of actions after the user interacts with an icon.
Use a `Menu` to display a list of actions after the user interacts with an icon.

**Don’t** use a `DropdownMenu` for important actions that should always be visible. Use a `Toolbar` instead.
**Don’t** use a `Menu` for important actions that should always be visible. Use a `Toolbar` instead.

**Don’t**
Don’t use a `DropdownMenu` for frequently used actions. Use a `Toolbar` instead.
Don’t use a `Menu` for frequently used actions. Use a `Toolbar` instead.

#### Behavior

Generally, the parent button should indicate that interacting with it will show a `DropdownMenu`.
Generally, the parent button should indicate that interacting with it will show a `Menu`.

The parent button should retain the same visual styling regardless of whether the `DropdownMenu` is displayed or not.
The parent button should retain the same visual styling regardless of whether the `Menu` is displayed or not.

#### Placement

The `DropdownMenu` should typically appear directly below, or below and to the left of, the parent button. If there isn’t enough space below to display the full `DropdownMenu`, it can be displayed instead above the parent button.
The `Menu` should typically appear directly below, or below and to the left of, the parent button. If there isn’t enough space below to display the full `Menu`, it can be displayed instead above the parent button.

## Development guidelines

This component is still highly experimental, and it's not normally accessible to consumers of the `@wordpress/components` package.

The component exposes a set of components that are meant to be used in combination with each other in order to implement a `DropdownMenu` correctly.
The component exposes a set of components that are meant to be used in combination with each other in order to implement a `Menu` correctly.

### `DropdownMenuV2`
### `Menu`

The root component, used to specify the menu's trigger and its contents.

Expand Down Expand Up @@ -112,7 +112,7 @@ The skidding of the popover along the anchor element. Can be set to negative val
- Required: no
- Default: `0` for root-level menus, `-8` for nested menus

### `DropdownMenuV2.Item`
### `Menu.Item`

Used to render a menu item.

Expand Down Expand Up @@ -152,7 +152,7 @@ Determines if the element is disabled.
- Required: no
- Default: `false`

### `DropdownMenuV2.CheckboxItem`
### `Menu.CheckboxItem`

Used to render a checkbox item.

Expand Down Expand Up @@ -218,7 +218,7 @@ Event handler called when the checked state of the checkbox menu item changes.

- Required: no

### `DropdownMenuV2.RadioItem`
### `Menu.RadioItem`

Used to render a radio item.

Expand Down Expand Up @@ -283,7 +283,7 @@ Event handler called when the checked radio menu item changes.

- Required: no

### `DropdownMenuV2.ItemLabel`
### `Menu.ItemLabel`

Used to render the menu item's label.

Expand All @@ -297,7 +297,7 @@ The label contents.

- Required: yes

### `DropdownMenuV2.ItemHelpText`
### `Menu.ItemHelpText`

Used to render the menu item's help text.

Expand All @@ -311,7 +311,7 @@ The help text contents.

- Required: yes

### `DropdownMenuV2.Group`
### `Menu.Group`

Used to group menu items.

Expand All @@ -325,7 +325,7 @@ The contents of the group.

- Required: yes

### `DropdownMenuV2.GroupLabel`
### `Menu.GroupLabel`

Used to render a group label. The label text should be kept as short as possible.

Expand All @@ -339,6 +339,6 @@ The contents of the group label.

- Required: yes

### `DropdownMenuV2.Separator`
### `Menu.Separator`

Used to render a visual separator.
28 changes: 14 additions & 14 deletions packages/components/src/menu/checkbox-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,51 @@ import { Icon, check } from '@wordpress/icons';
* Internal dependencies
*/
import type { WordPressComponentProps } from '../context';
import { DropdownMenuContext } from './context';
import type { DropdownMenuCheckboxItemProps } from './types';
import { MenuContext } from './context';
import type { MenuCheckboxItemProps } from './types';
import * as Styled from './styles';
import { useTemporaryFocusVisibleFix } from './use-temporary-focus-visible-fix';

export const DropdownMenuCheckboxItem = forwardRef<
export const MenuCheckboxItem = forwardRef<
HTMLDivElement,
WordPressComponentProps< DropdownMenuCheckboxItemProps, 'div', false >
>( function DropdownMenuCheckboxItem(
WordPressComponentProps< MenuCheckboxItemProps, 'div', false >
>( function MenuCheckboxItem(
{ suffix, children, onBlur, hideOnClick = false, ...props },
ref
) {
// TODO: Remove when https://github.com/ariakit/ariakit/issues/4083 is fixed
const focusVisibleFixProps = useTemporaryFocusVisibleFix( { onBlur } );
const dropdownMenuContext = useContext( DropdownMenuContext );
const menuContext = useContext( MenuContext );

return (
<Styled.DropdownMenuCheckboxItem
<Styled.MenuCheckboxItem
ref={ ref }
{ ...props }
{ ...focusVisibleFixProps }
accessibleWhenDisabled
hideOnClick={ hideOnClick }
store={ dropdownMenuContext?.store }
store={ menuContext?.store }
>
<Ariakit.MenuItemCheck
store={ dropdownMenuContext?.store }
store={ menuContext?.store }
render={ <Styled.ItemPrefixWrapper /> }
// Override some ariakit inline styles
style={ { width: 'auto', height: 'auto' } }
>
<Icon icon={ check } size={ 24 } />
</Ariakit.MenuItemCheck>

<Styled.DropdownMenuItemContentWrapper>
<Styled.DropdownMenuItemChildrenWrapper>
<Styled.MenuItemContentWrapper>
<Styled.MenuItemChildrenWrapper>
{ children }
</Styled.DropdownMenuItemChildrenWrapper>
</Styled.MenuItemChildrenWrapper>

{ suffix && (
<Styled.ItemSuffixWrapper>
{ suffix }
</Styled.ItemSuffixWrapper>
) }
</Styled.DropdownMenuItemContentWrapper>
</Styled.DropdownMenuCheckboxItem>
</Styled.MenuItemContentWrapper>
</Styled.MenuCheckboxItem>
);
} );
8 changes: 4 additions & 4 deletions packages/components/src/menu/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { createContext } from '@wordpress/element';
/**
* Internal dependencies
*/
import type { DropdownMenuContext as DropdownMenuContextType } from './types';
import type { MenuContext as MenuContextType } from './types';

export const DropdownMenuContext = createContext<
DropdownMenuContextType | undefined
>( undefined );
export const MenuContext = createContext< MenuContextType | undefined >(
ciampo marked this conversation as resolved.
Show resolved Hide resolved
undefined
);
16 changes: 8 additions & 8 deletions packages/components/src/menu/group-label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import { forwardRef, useContext } from '@wordpress/element';
* Internal dependencies
*/
import type { WordPressComponentProps } from '../context';
import { DropdownMenuContext } from './context';
import { MenuContext } from './context';
import { Text } from '../text';
import type { DropdownMenuGroupLabelProps } from './types';
import type { MenuGroupLabelProps } from './types';
import * as Styled from './styles';

export const DropdownMenuGroupLabel = forwardRef<
export const MenuGroupLabel = forwardRef<
HTMLDivElement,
WordPressComponentProps< DropdownMenuGroupLabelProps, 'div', false >
>( function DropdownMenuGroup( props, ref ) {
const dropdownMenuContext = useContext( DropdownMenuContext );
WordPressComponentProps< MenuGroupLabelProps, 'div', false >
>( function MenuGroup( props, ref ) {
const menuContext = useContext( MenuContext );
return (
<Styled.DropdownMenuGroupLabel
<Styled.MenuGroupLabel
ref={ ref }
render={
// @ts-expect-error The `children` prop is passed
Expand All @@ -31,7 +31,7 @@ export const DropdownMenuGroupLabel = forwardRef<
/>
}
{ ...props }
store={ dropdownMenuContext?.store }
store={ menuContext?.store }
/>
);
} );
16 changes: 8 additions & 8 deletions packages/components/src/menu/group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import { forwardRef, useContext } from '@wordpress/element';
* Internal dependencies
*/
import type { WordPressComponentProps } from '../context';
import { DropdownMenuContext } from './context';
import type { DropdownMenuGroupProps } from './types';
import { MenuContext } from './context';
import type { MenuGroupProps } from './types';
import * as Styled from './styles';

export const DropdownMenuGroup = forwardRef<
export const MenuGroup = forwardRef<
HTMLDivElement,
WordPressComponentProps< DropdownMenuGroupProps, 'div', false >
>( function DropdownMenuGroup( props, ref ) {
const dropdownMenuContext = useContext( DropdownMenuContext );
WordPressComponentProps< MenuGroupProps, 'div', false >
>( function MenuGroup( props, ref ) {
const menuContext = useContext( MenuContext );
return (
<Styled.DropdownMenuGroup
<Styled.MenuGroup
ref={ ref }
{ ...props }
store={ dropdownMenuContext?.store }
store={ menuContext?.store }
/>
);
} );
Loading
Loading