-
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
Extend input type check in selection capabilities (#12062) #12135
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import Fixture from '../../Fixture'; | ||
|
||
const React = window.React; | ||
|
||
class ReplaceEmailInput extends React.Component { | ||
state = { | ||
formSubmitted: false, | ||
}; | ||
|
||
onReset = () => { | ||
this.setState({formSubmitted: false}); | ||
}; | ||
|
||
onSubmit = event => { | ||
event.preventDefault(); | ||
this.setState({formSubmitted: true}); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<Fixture> | ||
<form className="control-box" onSubmit={this.onSubmit}> | ||
<fieldset> | ||
<legend>Email</legend> | ||
{!this.state.formSubmitted ? ( | ||
<input type="email" /> | ||
) : ( | ||
<input type="text" disabled={true} /> | ||
)} | ||
</fieldset> | ||
</form> | ||
<button type="button" onClick={this.onReset}> | ||
Reset | ||
</button> | ||
</Fixture> | ||
); | ||
} | ||
} | ||
|
||
export default ReplaceEmailInput; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,11 +22,21 @@ function isInDocument(node) { | |
* Input selection module for React. | ||
*/ | ||
|
||
/** | ||
* @hasSelectionCapabilities: we get the element types that support selection | ||
* from https://html.spec.whatwg.org/#do-not-apply, looking at `selectionStart` | ||
* and `selectionEnd` rows. | ||
*/ | ||
export function hasSelectionCapabilities(elem) { | ||
const nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase(); | ||
return ( | ||
nodeName && | ||
((nodeName === 'input' && elem.type === 'text') || | ||
((nodeName === 'input' && | ||
(elem.type === 'text' || | ||
elem.type === 'search' || | ||
elem.type === 'tel' || | ||
elem.type === 'url' || | ||
elem.type === 'password')) || | ||
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. Why is email not in this list? 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. Sorry. That was very blunt! Should So this matches up with the Would it be possible to add a comment at the top of this block that references this table for future contributors? 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. I will add a comment containing the link as well. As far as I can see we are only using the |
||
nodeName === 'textarea' || | ||
elem.contentEditable === 'true') | ||
); | ||
|
@@ -52,7 +62,10 @@ export function restoreSelection(priorSelectionInformation) { | |
const priorFocusedElem = priorSelectionInformation.focusedElem; | ||
const priorSelectionRange = priorSelectionInformation.selectionRange; | ||
if (curFocusedElem !== priorFocusedElem && isInDocument(priorFocusedElem)) { | ||
if (hasSelectionCapabilities(priorFocusedElem)) { | ||
if ( | ||
priorSelectionRange !== null && | ||
hasSelectionCapabilities(priorFocusedElem) | ||
) { | ||
setSelection(priorFocusedElem, priorSelectionRange); | ||
} | ||
|
||
|
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.
For new test cases that are stateful, can you break it out into it's own component? See NumberInputExtraZeroes.js as an example.
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.
I was in doubt about the implementation. Thanks for the guideline!