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/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Enhancements

- `ColorPalette`, `BorderControl`: Don't hyphenate hex value in `aria-label` ([#52932](https://github.com/WordPress/gutenberg/pull/52932)).
- `MenuItemsChoice`, `MenuItem`: Support a `disabled` prop on a menu item ([#52737](https://github.com/WordPress/gutenberg/pull/52737)).

### Bug Fix

Expand Down
7 changes: 7 additions & 0 deletions packages/components/src/menu-item/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ MenuItem supports the following props. Any additional props are passed through t

Element to render as child of button.

### `disabled`

- Type: `boolean`
- Required: No

Refer to documentation for [Button's `disabled` prop](/packages/components/src/button/README.md#disabled-boolean).

### `info`

- Type: `string`
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/menu-items-choice/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function MenuItemsChoice( {
<MenuItem
key={ item.value }
role="menuitemradio"
disabled={ item.disabled }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this adds another possible prop to the allowed choices, this likely needs to be updated in the component README here:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included a mention in menu-item/README.md: 7cddb17

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another side comment - I think this change is worth getting a components package CHANGELOG entry.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a changelog entry 6e2744c

icon={ isSelected && check }
info={ item.info }
isSelected={ isSelected }
Expand Down
5 changes: 5 additions & 0 deletions packages/components/src/menu-items-choice/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Internal dependencies
*/
import type { ShortcutProps } from '../shortcut/types';
import type { ButtonAsButtonProps } from '../button/types';

export type MenuItemsChoiceProps = {
/**
Expand Down Expand Up @@ -38,6 +39,10 @@ export type MenuItemChoice = {
* Unique value for choice.
*/
value: string;
/**
* Whether the menu item is disabled.
*/
disabled?: ButtonAsButtonProps[ 'disabled' ];
/**
* Additional information which will be rendered below the given label.
*/
Expand Down
27 changes: 23 additions & 4 deletions packages/edit-post/src/components/header/mode-switcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,31 @@ function ModeSwitcher() {
return null;
}

if ( ! isRichEditingEnabled || ! isCodeEditingEnabled ) {
return null;
let selectedMode = mode;
if ( ! isRichEditingEnabled && mode === 'visual' ) {
selectedMode = 'text';
}
if ( ! isCodeEditingEnabled && mode === 'text' ) {
selectedMode = 'visual';
}

const choices = MODES.map( ( choice ) => {
if ( choice.value !== mode ) {
if ( ! isCodeEditingEnabled && choice.value === 'text' ) {
choice = {
...choice,
disabled: true,
};
}
if ( ! isRichEditingEnabled && choice.value === 'visual' ) {
choice = {
...choice,
disabled: true,
info: __(
'You can enable the visual editor in your profile settings.'
),
};
}
if ( choice.value !== selectedMode && ! choice.disabled ) {
return { ...choice, shortcut };
}
return choice;
Expand All @@ -70,7 +89,7 @@ function ModeSwitcher() {
<MenuGroup label={ __( 'Editor' ) }>
<MenuItemsChoice
choices={ choices }
value={ mode }
value={ selectedMode }
onSelect={ switchEditorMode }
/>
</MenuGroup>
Expand Down