You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cursor jumps when backspacing in a number input (with ShadowDOM) #11827
Do you want to request a feature or report a bug?
bug
What is the current behavior?
Number inputs with decimal values in Chrome ShadowDOM do not maintain cursor position as user backspaces in the input field.
Super low-quality gif (sorry):
This issue appears to be similar to the problem here: #7359, but in this case it's only custom elements with a shadow root that exhibit the problem.
Have a React component render a number input: <input type="number" />.
Attach that React component as part of the ShadowDOM node of a custom element.
Enter in some decimal value (e.g., 88.88) into the input.
Slowly backspace in the input. As soon as the decimal point would be the last character, the decimal point is removed and the cursor position jumps to the beginning of the input.
The ShadowDOM case behaves like the other cases: when backspacing in the input, the cursor does not jump to the beginning of the input and the decimal point is not unexpectedly deleted.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React 16.2.0 + Chrome 62.0.3202.62 + OSX 10.12.6
Reacted by Samphan Raruenrom, fmsthird and Sobhan Niroula
if (
// Focused number inputs synchronize on blur. See ChangeEventPlugin.js
type !== 'number' ||
node.ownerDocument.activeElement !== node
) {
We only assign the value attribute on a number input if it isn't the currently focused element. This is designed to specifically avoid this issue because Chrome reformats number inputs (dropping decimal places) when you assign the value attribute to a number input.
This is to keep it as similar to other inputs as possible. I wonder if the input is never the active element in the case of a Shadow DOM.
changed the title [-]Cursor jumps when backspacing in a number input (+ ShadowDOM)[/-][+]Cursor jumps when backspacing in a number input (with ShadowDOM)[/+]on Jan 2, 2018
Help
while i am tried to replicate this issue on my local mission with fixtures in https://github.com/facebook/react/ , i am getting an error like this TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
Is this still known to be a problem? The fiddle mentioned in the original issue seems to work correctly now. I tried specifically setting the React version in the fiddle to 16.2.0 but it still works.
Hmm, yeah I can no longer reproduce either on the fiddle or when testing out some components on another project. Maybe this got fixed with an update to Chrome?
Activity
nhunzaker commentedon Dec 11, 2017
Oooh boy :). I wonder if this is happening because this line here:
https://github.com/facebook/react/blob/master/packages/react-dom/src/client/ReactDOMFiberInput.js#L310
We only assign the value attribute on a number input if it isn't the currently focused element. This is designed to specifically avoid this issue because Chrome reformats number inputs (dropping decimal places) when you assign the value attribute to a number input.
This is to keep it as similar to other inputs as possible. I wonder if the input is never the active element in the case of a Shadow DOM.
YellowKirby commentedon Dec 11, 2017
Yeah, that
activeElementline seemed a little suspect to me, but I haven't done much digging into the React codebase.https://developers.google.com/web/fundamentals/web-components/shadowdom#focus has a simple function that will walk the shadowDOM in the case where
activeElementdoes have a shadow root:[-]Cursor jumps when backspacing in a number input (+ ShadowDOM)[/-][+]Cursor jumps when backspacing in a number input (with ShadowDOM)[/+]chrisdieckhaus commentedon Jan 7, 2018
I'd be interested in taking a stab at this.
react#11827 Compare node to shadow DOM element root activeElement whe…
avinashdvv commentedon Jan 14, 2018
Help
while i am tried to replicate this issue on my local mission with fixtures in
https://github.com/facebook/react/, i am getting an error like thisTypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function.code
YellowKirby commentedon Jan 15, 2018
@avinashdvv AFAIK that issue is happening because of the way babel typically transpiles ES6 classes. babel/babel#4480
You might need to add a plugin like https://github.com/WebReflection/babel-plugin-transform-builtin-classes in order for it to work correctly.
OliverRadini commentedon Apr 1, 2021
Is this still known to be a problem? The fiddle mentioned in the original issue seems to work correctly now. I tried specifically setting the React version in the fiddle to 16.2.0 but it still works.
YellowKirby commentedon Apr 2, 2021
Hmm, yeah I can no longer reproduce either on the fiddle or when testing out some components on another project. Maybe this got fixed with an update to Chrome?
matthewoates commentedon Apr 30, 2021
I can't reproduce this issue either.