Repository navigation
Conversation
Move the checked state, toggling and announcement of the preference menu items into a private `usePreferenceToggle` hook of the preferences package, and use it in `PreferenceToggleMenuItem` and the `MoreMenuPreferenceItem` copies of the editor, the widgets editor and the widgets Customizer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011g9URxg61iAc4ZxQiqFamu
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: -26 B (0%) Total Size: 8.85 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. region-scoped focus that refrains on traversals in
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011g9URxg61iAc4ZxQiqFamu
| * @param options.label Label of the preference. | ||
| * @param options.messageActivated Message announced on activation. | ||
| * @param options.messageDeactivated Message announced on deactivation. | ||
| * @param options.handleToggling Whether the hook toggles the preference. |
There was a problem hiding this comment.
The handleToggling kind of conflicts with the hook's name/purpose, which implies that preferences are toggled.
There was a problem hiding this comment.
Good point. In 8ae1bf6, I replaced handleToggling and onToggle with a toggle option, which defaults to toggling the preference in the store.
The hook now always toggles the preference and announces it. The `toggle` option only replaces how the preference is toggled, which distraction free mode needs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011g9URxg61iAc4ZxQiqFamu
…ference-item-hook
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011g9URxg61iAc4ZxQiqFamu
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011g9URxg61iAc4ZxQiqFamu
| toggle: handleToggling ? undefined : () => onToggle?.(), | ||
| } ); | ||
|
|
||
| return ( | ||
| <MenuItem | ||
| icon={ isActive ? check : null } | ||
| isSelected={ isActive } | ||
| onClick={ () => { | ||
| onToggle(); | ||
| if ( handleToggling ) { | ||
| toggle( scope, name ); | ||
| onToggle?.(); | ||
| } | ||
| speakMessage(); | ||
| toggle(); | ||
| } } |
There was a problem hiding this comment.
Nit, optional: onToggle gets called from two places here. We could pass toggle: handleToggling ? undefined : () => {} and always call onToggle?.(); toggle(); instead. Same order, and the editor copy could do the same.
What?
Menufrom@wordpress/ui#87622Menufrom@wordpress/ui#87622 (review)Moves the shared checked state, toggling, and announcement logic of the preference menu items into a private
usePreferenceTogglehook in@wordpress/preferences.Why?
After #87622, the same logic lived in four places:
PreferenceToggleMenuItemin@wordpress/preferencesMoreMenuPreferenceItemin@wordpress/editorMoreMenuPreferenceItemin@wordpress/edit-widgetsMoreMenuPreferenceItemin@wordpress/customize-widgetsThe copies are needed because
@wordpress/uiis bundled into each package, so theMenuparts can't be rendered by the preferences package, but the logic itself can be shared.How?
Adds a private
usePreferenceTogglehook to@wordpress/preferences, which reads the preference, toggles it and announces the change, and uses it inPreferenceToggleMenuItemand the threeMoreMenuPreferenceItemcomponents.There are no user-facing changes.
Testing Instructions
Use of AI Tools
This PR was authored with Claude Code, and reviewed by the author.
Generated by Claude Code