Skip to content

Commit

Permalink
hasSelectionCapabilities: email, tel and url input-fields can have se…
Browse files Browse the repository at this point in the history
…lections too (fixes problem when input field changes type on dynamically)
  • Loading branch information
adrianimboden committed Jan 20, 2018
1 parent 4ca7855 commit db923b8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/react-dom/src/client/ReactInputSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ 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 == "email" || elem.type == "tel" || elem.type == "url")

This comment has been minimized.

Copy link
@leonascimento

leonascimento Jan 30, 2018

Hi @adrianimboden, I'm thinking that you can improve using this code.
What do you think?

['text', 'email', 'tel'].indexOf(elem.type) >= 0
) ||
nodeName === 'textarea' ||
elem.contentEditable === 'true')
);
Expand Down

2 comments on commit db923b8

@adrianhelvik
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or what about

typeof elem.selectionStart === 'number'

@adrianimboden
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, once I get on to implement a proper fix, I will take your suggestions into account.

Please sign in to comment.