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
prevent firefox marking required textareas invalid #16578
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,33 @@ describe('ReactDOMTextarea', () => { | |
expect(node.value).toEqual('gorilla'); | ||
}); | ||
|
||
it('will not initially assign an empty value (covers case where firefox throws a validation error when required attribute is set)', () => { | ||
const container = document.createElement('div'); | ||
|
||
let counter = 0; | ||
const originalCreateElement = document.createElement; | ||
spyOnDevAndProd(document, 'createElement').and.callFake(function(type) { | ||
const el = originalCreateElement.apply(this, arguments); | ||
let value = ''; | ||
if (type === 'textarea') { | ||
Object.defineProperty(el, 'value', { | ||
get: function() { | ||
return value; | ||
}, | ||
set: function(val) { | ||
value = '' + val; | ||
counter++; | ||
}, | ||
}); | ||
} | ||
return el; | ||
}); | ||
|
||
ReactDOM.render(<textarea value="" readOnly={true} />, container); | ||
|
||
expect(counter).toEqual(0); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For others - we pulled this test from I still think this is a weird test, and I wonder if it makes sense to create a common helper for this sort of thing. |
||
|
||
it('should render defaultValue for SSR', () => { | ||
const markup = ReactDOMServer.renderToString(<textarea defaultValue="1" />); | ||
const div = document.createElement('div'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain this a bit better? I do see a red outline specifically when I focus the "Empty value prop string" textarea, hit any character on the keyboard, and then move the focus to one of the other textareas. Is this expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Great catch! I don't think there is anything we can do about this though, assuming this is what's happening:
So controlling the input is at odds with input validation. I think this is okay for fields that don't allow any text input because they should really have
readOnly
on them instead of a blank change callback.I think these are setup this way to avoid needing to scaffold out the controlled input code. Would it be less confusing if they were set up this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that seems reasonable. Maybe update the instructions then to be clearer about this case.
Not quite sure what you mean by that but I think what we have now is already better than what we had 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! I just meant adding the callbacks and state for the controlled inputs so that the values are editable. Right now we don't have them, I think because it isn't essential for the fixture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated expected result to read "...see a red aura on initial page load, indicating the textarea is invalid..."
do you think this is sufficient clarification?