-
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
Improve the useDisabled hook and Disabled component #40631
Conversation
return useRefEffect( ( node ) => { | ||
const disable = () => { | ||
node.style.setProperty( 'user-select', 'none' ); | ||
node.style.setProperty( '-webkit-user-select', 'none' ); |
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.
This change means you can select text inside a disabled element. For instance, I noticed that when double clicking a paragraph it would get selected even it had a "group" parent, that's because the "useSelectionObserver" hook would have triggered anyway. Preventing browser selection solves this.
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.
Do you mean whole block or just the text?
I would expect text to be selectable even if component is disabled. Mostly for copy/pasting.
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.
text as well. I'm not sure text should be selectable. Think patterns previews and stuff like that. Don't we want these things to behave more like "images".
Also, I'm not sure how I can fix the useSelectionObserver bug if I don't disable selection 😬
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 think disabling text selection for previews is okay, but will be more problematic UX decision for blocks in the editor.
There are few blocks that use Disabled component.
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 problem is that there's no way to know that a block is "disabled", it's not something in state. so there's no way to disabled useSelectionObserver when a block is disabled. So I'm not sure how to solve that otherwise.
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.
Good point 😅 I’m okay shipping the fix like this and keeping eye on the feedback.
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.
useSelectionObserver bug
That's a tricky one. What problem does this cause in practice?
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.
Right now in trunk "nothing" but I'm considering using useDisabled to disable blocks for several things:
- exploded mode
- block overlay (template parts and reusable blocks)
- potentially locking as well
The problem is that useSelectionObserver triggers, clicking a block will select it even if it's a child of a disabled block.
focusable instanceof | ||
node.ownerDocument.defaultView.HTMLElement | ||
) { | ||
focusable.style.setProperty( 'pointer-events', 'none' ); |
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.
This is another addition in this PR. Basically any clickable item inside the disabled element is now "non clickable"
Size Change: -203 B (0%) Total Size: 1.23 MB
ℹ️ View Unchanged
|
88a2241
to
468a006
Compare
Rebased this, so now it's just about adding stuff to useDisabled and use it in Disabled component. Should be ready for a ✅ |
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 changes here look good to me. But let’s keep eye on text selection issue report 😁
Ok let's try this. |
What?
The idea here is to improve useDisabled a bit in order to potentially use it for exploded mode or the block content overlay (template part, reusable blocks).
The PR also includes a small consolidation: I'm using the hook in the Disabled component instead of duplicating its code.
Why?
We need to figure out a way to disable block that is not fragile. Potentially we could leverage it for exploded mode.
How?
What I did to implement this is that I've used "useDisabled" in "useBlockProps" meaning all blocks would be disabled by default and I try selecting a container block (group) and I've tried to fixed all the cases where the child block would get selected anyway.
Note Right now when using the hook, it's a one way modification of the DOM, meaning we can restore a "non disabled" state and if we ever want to use the hook in exploded mode, we'd need a way to "restore" the enabled state. This behavior is not included in this PR.