Skip to content
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

textarea with required attribute renders in invalid state in FF #16402

Closed
dlaub3 opened this issue Aug 15, 2019 · 3 comments · Fixed by #16578
Closed

textarea with required attribute renders in invalid state in FF #16402

dlaub3 opened this issue Aug 15, 2019 · 3 comments · Fixed by #16578

Comments

@dlaub3
Copy link

dlaub3 commented Aug 15, 2019

Bug

When a textarea has the required attribute it renders in the invalid state using FireFox.

This behavior is visible here: https://codesandbox.io/s/rough-frog-f00ow. Remember to view it in FireFox.

I expect the required field to validate on form submit and not before.

I have tested this with FireFox 68 and 69 and React 16.8.6

This appears appears to be a re-occurrence of: #8395

@matjack1
Copy link

I'm experiencing this as well

@nhunzaker
Copy link
Contributor

nhunzaker commented Aug 26, 2019

Uh oh. There was a fix for this for inputs, but the textarea code path is different:

// Otherwise, do not re-assign the value property if is empty. This
// potentially avoids a DOM write and prevents Firefox (~60.0.1) from
// prematurely marking required inputs as invalid. Equality is compared
// to the current value in case the browser provided value is not an
// empty string.
if (isButton || value !== node.value) {
node.value = toString(value);
}
}

This probably needs to happen on the textarea side too. Probably somewhere in here:

export function postMountWrapper(element: Element, props: Object) {
const node = ((element: any): TextAreaWithWrapperState);
// This is in postMount because we need access to the DOM node, which is not
// available until after the component has mounted.
const textContent = node.textContent;
// Only set node.value if textContent is equal to the expected
// initial value. In IE10/IE11 there is a bug where the placeholder attribute
// will populate textContent as well.
// https://developer.microsoft.com/microsoft-edge/platform/issues/101525/
if (textContent === node._wrapperState.initialValue) {
node.value = textContent;
}
}

I think I can fix this pretty quickly, but won't be able to get to it until later in the week if anyone else would like to pick it up.

@nhunzaker
Copy link
Contributor

Just talked with @halvves about taking a stab at this!

nhunzaker pushed a commit that referenced this issue Sep 18, 2019
* prevent firefox marking required textareas invalid

Bug was caused by an IE10/IE11 bugfix dealing with the placeholder attribute and textContent. Solved by avoiding the IE bugfix when textContent was empty.

Closes #16402

* more explicit conditional check for textContent

re: @philipp-spiess code review

* clarify textarea test fixture's expected result

better describe the behavior we are testing for
re: @philipp-spiess code review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants