-
Notifications
You must be signed in to change notification settings - Fork 47.7k
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
Cursor jumps when backspacing in a number input (with ShadowDOM) #11827
Comments
Oooh boy :). I wonder if this is happening because this line here:
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. |
Yeah, that https://developers.google.com/web/fundamentals/web-components/shadowdom#focus has a simple function that will walk the shadowDOM in the case where function deepActiveElement() {
let a = document.activeElement;
while (a && a.shadowRoot && a.shadowRoot.activeElement) {
a = a.shadowRoot.activeElement;
}
return a;
} |
I'd be interested in taking a stab at this. |
…when setting defaultValue
Help code
|
@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. |
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? |
I can't reproduce this issue either. |
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.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar (template for React 16: https://jsfiddle.net/Luktwrdm/, template for React 15: https://jsfiddle.net/hmbg7e9w/).
<input type="number" />
.88.88
) into the input.Demo: https://jsfiddle.net/69z2wepo/94566/
What is the expected behavior?
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
The text was updated successfully, but these errors were encountered: