slate icon indicating copy to clipboard operation
slate copied to clipboard

Clicking an HTML button won't update editor's focus state

Open htulipe opened this issue 4 years ago • 5 comments

Do you want to request a feature or report a bug?

Bug

What's the current behavior?

In the linked fiddle I have an editor, a component that display current useFocused value and a simple button. If one clicks inside the editor or anywhere in the page, the focus state is updated. It's not the case when one clicks the button. If the editor was focused, it will still be reported as focused.

Fiddle https://jsfiddle.net/3er0m7nv/6/

Gif 2020-09-28 15 15 37

Slate: 0.58.3 Browser: Chrome OS: Mac

What's the expected behavior?

I'd expect the editor "focused" state to be updated when clicking a button.

Thanks

htulipe avatar Sep 28 '20 13:09 htulipe

Note that the button can be inside or outside the Slate component, the bug is still there.

htulipe avatar Sep 28 '20 13:09 htulipe

It‘s not a bug. you can add event to html button like that: `onMouseDown={e=>{ e.preventDefault(); //do something you want

}}`

ls19930101 avatar Oct 16 '20 09:10 ls19930101

It is a bug in the sense that the editor is reported as focused while it's not. I'm not looking for a way to listen to click event on button, I want the editor focus state to match the reality.

htulipe avatar Oct 16 '20 09:10 htulipe

I have the same issue. Clicking regular elements outside the editor will blur the element on mousedown. Clicking any <button> element sometimes blurs on full click (mousedown is not enough), and some times doesn't blur at all.

The same issue happens for me when programmatically .focus()ing another element or .blur()ing the <Editable/> element itself. CodeSandbox

I'm guessing it has something to do with the way Slate uses the selectionchange event for focus behavior.

sebastianseilund avatar Nov 11 '20 21:11 sebastianseilund

I have the same issue. Clicking regular elements outside the editor will blur the element on mousedown. Clicking any <button> element sometimes blurs on full click (mousedown is not enough), and some times doesn't blur at all.

The same issue happens for me when programmatically .focus()ing another element or .blur()ing the element itself. CodeSandbox

I'm guessing it has something to do with the way Slate uses the selectionchange event for focus behavior.

I got around this by using <div role="button" /> component instead of using <button>

leeran7 avatar Apr 17 '24 19:04 leeran7