-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Patterns: Disable the preview option button when editing #53913
Conversation
Size Change: +29 B (0%) Total Size: 1.51 MB
ℹ️ View Unchanged
|
Flaky tests detected in 758e448. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6012820323
|
Thanks for the PR. Much appreciated 🙇 I would like a confidence check from @WordPress/gutenberg-design to ensure that we're taking the right action here to hide the device previews.
Let's make sure Design are happy with this assumption. |
Good instincts, and thanks for the ping. Instead of hiding it, can we disable it? |
Should the device shortcuts and resize handles be mutually exclusive? I'm wondering if they can still be useful for quickly jumping between specific sizes, without having to fiddle with the handles? |
Thanks for the advice, @jasmussen, @jameskoster!
I have updated using this approach.
I, too, think this behavior is ideal. Having the resize handle and preview option available at the same time could be considered as a follow-up. |
What's the point of keeping it disabled? Usually, the disabled button becomes enabled when some requirements are met, but this isn't the case here - the button can't be enabled based on user actions. |
A few reasons:
|
Thanks for the clarification, @jasmussen! |
<PreviewOptions | ||
deviceType={ deviceType } | ||
setDeviceType={ setPreviewDeviceType } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PreviewOptions
component has an isEnabled
prop that can handle this state for us. You don't need to render components conditionally.
Side note: Disabling the toggle doesn't match a11y best practices, but that's a matter of general component improvement and shouldn't be a blocker here.
Thanks for the review, @Mamaduka! I have updated this PR using the |
@@ -33,6 +33,7 @@ export default function PreviewOptions( { | |||
const toggleProps = { | |||
className: 'block-editor-post-preview__button-toggle', | |||
disabled: ! isEnabled, | |||
__experimentalIsFocusable: ! isEnabled, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added this prop to make the dropdown focusable even when it is disabled and to show the tooltip. This change will also affect the preview option button in the Post Editor. Do you think this should not be added in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that's fine and a good improvement here.
I just realized that we also need to set disableOpenOnArrowDown
based on the enabled status to avoid the opening drop via the arrow-down key. Pushed changes here 758e448.
Screencast
CleanShot.2023-08-29.at.17.13.47.mp4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for finding it, @Mamaduka!
I have fixed the E2E test failure in 70e6e63. The failing part was the expectation that the preview button would not appear in Storybook. This PR will cause a disabled preview button to appear, but I think this is the expected behavior. As mentioned in this comment, when device shortcuts and resize handles work together in the future, this button should also be available on the StyleBook page. |
@@ -42,7 +42,7 @@ test.describe( 'Style Book', () => { | |||
).not.toBeVisible(); | |||
await expect( | |||
page.locator( 'role=button[name="View"i]' ) | |||
).not.toBeVisible(); | |||
).toHaveAttribute( 'aria-disabled', 'true' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use .toBeDisabled()
here. It checks both disabled
and aria-disabled
.
Ref: https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-be-disabled.
Fixes: #53862
Follow-up on: #52427
What?
This PR
removesdisables the header device preview button in the pattern edit mode.Why?
The pattern edit page should not need this button, as the canvas is resizable by handles, as are the template parts and navigation.
How?
I have discovered that there is a
FOCUSABLE_ENTITIES
constant that defines whether the current entity is focusable or not.I moved
constant.js
to the proper location to reuse this constant. This will prevent regression if editable entities are updated in the future.Testing Instructions
not displayeddisabled in the header.