Skip to content

Commit

Permalink
Rename isOpen to open
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewserong committed Sep 7, 2023
1 parent 19d73b8 commit 19f88d3
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,22 @@ export function BlockSettingsDropdown( {
const parentBlockIsSelected =
selectedBlockClientIds?.includes( firstParentClientId );

// Only override the isOpen prop if the current block is not the one that
// Only override the `open` prop if the current block is not the one that
// opened the menu. The logic here is to ensure that non-current
// block menus are automatically closed when a new block menu is opened.
// This is useful for cases where focus is not present in the current window.
// All other behavior of the drop down menu should be otherwise unaffected.
const isOpen =
const open =
! currentClientId || openedBlockSettingsMenu === currentClientId
? undefined
: false;

const onToggle = useCallback(
( localIsOpen ) => {
( localOpen ) => {
// When the current menu is opened, update the state to reflect
// the new current menu. This allows all other instances of the
// menu to close if they already open.
if ( localIsOpen ) {
if ( localOpen ) {
setOpenedBlockSettingsMenu( currentClientId );
}
},
Expand Down Expand Up @@ -238,7 +238,7 @@ export function BlockSettingsDropdown( {
label={ __( 'Options' ) }
className="block-editor-block-settings-menu"
popoverProps={ POPOVER_PROPS }
isOpen={ isOpen }
open={ open }
onToggle={ onToggle }
noIcons
menuProps={ {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- Making Circular Option Picker a `listbox`. Note that while this changes some public API, new props are optional, and currently have default values; this will change in another patch ([#52255](https://github.com/WordPress/gutenberg/pull/52255)).
- `ToggleGroupControl`: Rewrite backdrop animation using framer motion shared layout animations, add better support for controlled and uncontrolled modes ([#50278](https://github.com/WordPress/gutenberg/pull/50278)).
- `Popover`: Add the `is-positioned` CSS class only after the popover has finished animating ([#54178](https://github.com/WordPress/gutenberg/pull/54178)).
- `Dropdown` and `DropdownMenu` allow controlled `isOpen` prop. `DropdownMenu` allow `onToggle` callback ([#54083](https://github.com/WordPress/gutenberg/pull/54083)).
- `Dropdown` and `DropdownMenu` allow controlled `open` prop. `DropdownMenu` allow `onToggle` callback ([#54083](https://github.com/WordPress/gutenberg/pull/54083)).

### Bug Fix

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/dropdown-menu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ A class name to apply to the dropdown menu's toggle element wrapper.

- Required: No

### `isOpen`: `boolean`
### `open`: `boolean`

Control whether the dropdown is open or not.

Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/dropdown-menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function UnconnectedDropdownMenu( dropdownMenuProps: DropdownMenuProps ) {
className,
controls,
icon = menu,
isOpen: isOpenProp,
open: openProp,
label,
popoverProps,
toggleProps,
Expand Down Expand Up @@ -94,7 +94,7 @@ function UnconnectedDropdownMenu( dropdownMenuProps: DropdownMenuProps ) {
return (
<Dropdown
className={ className }
isOpen={ isOpenProp }
open={ openProp }
onToggle={ onToggleProp }
popoverProps={ mergedPopoverProps }
renderToggle={ ( { isOpen, onToggle } ) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/dropdown-menu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export type DropdownMenuProps = {
/**
* Whether the dropdown is opened or not.
*/
isOpen?: boolean;
open?: boolean;
/**
* A human-readable label to present as accessibility text on the focused
* collapsed menu button.
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/dropdown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Set this to customize the text that is shown in the dropdown's header when it is

- Required: No

### `isOpen`: `boolean`
### `open`: `boolean`

Control whether the dropdown is open or not.

Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const UnconnectedDropdown = (
onClose,
onToggle,
style,
isOpen: isOpenProp,
open: openProp,

// Deprecated props
position,
Expand Down Expand Up @@ -78,7 +78,7 @@ const UnconnectedDropdown = (
const [ isOpenState, setIsOpen ] = useObservableState( false, onToggle );

// Allow provided `isOpen` prop to override internal state.
const isOpen = isOpenProp ?? isOpenState;
const isOpen = openProp ?? isOpenState;

useEffect(
() => () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/dropdown/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export type DropdownProps = {
/**
* Whether the dropdown is opened or not.
*/
isOpen?: boolean;
open?: boolean;
/**
* A callback invoked when the popover should be closed.
*/
Expand Down

0 comments on commit 19f88d3

Please sign in to comment.