setTimeout to allow closing Link UI on second click#59626
Conversation
|
Size Change: +89 B (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
|
This works well until I try to move between two different links: |
|
Thanks for attempting another route. I am slightly concerned that adding more "hacks" (your words not mine 😅) could compound what is already a complex set of interactions. It's good to have this exploration though 🙇 |
|
This is now testing well for me. One thing we could do to mitigate the risk of having so much code that we are unhappy with, is to make a PR that removes all the "hacks", so at least we have them documented, and then once the underlying issues are fixed we can merge that PR... |
Me too. I don't see a way around not adding a However, this isn't the most egregious hack. It's definitely not "the react way" though. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If 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. |
|
Applying this patch:
|
The main one is that we have to have a way to reset it to zero to allow a click on the link or toolbar button to open the popover:
We'd need a timeout to reset the clickCount to 0 which brings us back to relying on a timeout 😞 |
|
|
This still does add a feature that is otherwise missing (second click on the link button or link text to close the popover). We don't need to cherry-pick it, but I think it will work in tandem with #59635 after rebasing and fixing. I'd like to leave it open to discuss if it's still a worthwhile feature. |
…i from opening again. We can't toggle the addingLink state via the link because the onFocusOutside event fires to close the popover, and a the click on the inline link opens the link control again. A better fix to this issue would be to have the onFocusOutside event report the correct element that was clicked, and we could check the element that was clicked.
23d93b1 to
f488294
Compare
|
I don’t think a second click to close the popover for links is a worthwhile feature. Now that Also other formats have their UI active all the time (e.g. bold) it doesn’t disappear. |
What?
We need a second click on the same link to close the link popover
Why?
Otherwise, you can't place the caret within the editor to edit link text. The popover will always steal focus.
How?
Add a clickDelay via a 100ms setTimeout to prevent the link control ui from opening again.
We can't toggle the
addingLinkstate via the link because theonFocusOutsideevent fires to close the popover, and a the click on the inline link opens the link control again. A better fix to this issue would be to have theonFocusOutsideevent report the correct element that was clicked, and we could check the element that was clicked. Since we can't do that, the current flow looks like:setAddingLink( true )onFocusOutside:setAddingLink( false )setAddingLink( true )Flow from this PR:
setAddingLink( true )opendBy.current = event.targetonFocusOutside:setAddingLink( false )clickTimeoutId.current = setTimeout( () => { clickTimeout.current = false; }, 100 );clickTimeout.currentandopendByis the same element that was clicked.Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast