Slate: Focus is stolen from input and textarea elements in void nodes

Created on 20 Dec 2018  Â·  5Comments  Â·  Source: ianstormtaylor/slate

Do you want to request a _feature_ or report a _bug_?

bug

What's the current behavior?

Focus from input and textarea controls have their focus stolen when clicked, even though they are rendered as void nodes. If the controls are tabbed into, the focus remains.

May be a regression of this issue: https://github.com/ianstormtaylor/slate/issues/1744

JSFiddle: https://jsfiddle.net/rfeltis/fj9dvhom/2742/

image

OS: macOS Mojave 10.41.1
Browser: Chrome 71.0.3578.98 and Firefox 64.0

What's the expected behavior?

The focus stays inside of the input and textarea fields.

bug ♥ help

Most helpful comment

All 5 comments

Hello, I have the same issue, @zhujinxuan @rfeltis did you found a workaround ?

By capturing onBlur event on my <input>, I see that the code responsible for un-focusing is the one below.
Basically, there is a inconsistency between activeElement (which is the input) that is not the editor itself, and the editor is considered to be focused (selection.isFocused=true)

https://github.com/ianstormtaylor/slate/blob/13107b0c437fe0e84231c87f6e7887f6defc08c8/packages/slate-react/src/components/content.js#L175-L180

Hello, I have the same issue, @zhujinxuan @rfeltis did you found a workaround ?

@nicoxx As a workaround, we added preventDefault/stopPropagation to the click handler of our inputs. Fixes it for the time being.

As an aside, I spent a few hours tracking down similar behavior in my app today. The short version is, if you have ANY onBlur handler attached to the Editor, preventDefault/stopPropagation workaround stops working and you can no longer focus inputs within a void node.

Simplest demonstration is to add onBlur={() => {}} to the https://www.slatejs.org/#/embeds example. You can then no longer click on the video and edit the link. Also, maybe a related bug, if you actually type anything in the input without the onBlur, focus is maintained, but your cursor is moved to the end of the input.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vdms picture vdms  Â·  3Comments

yalu picture yalu  Â·  3Comments

ianstormtaylor picture ianstormtaylor  Â·  3Comments

YurkaninRyan picture YurkaninRyan  Â·  3Comments

chriserickson picture chriserickson  Â·  3Comments