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
Select polyfill alt #2335
base: select-polyfill
Are you sure you want to change the base?
Select polyfill alt #2335
Conversation
Size Change: +73 B (0%) Total Size: 38.6 kB
ℹ️ View Unchanged
|
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 like it 😃
// Fix onInput not firing on select/radio/checkbox in Edge <= 18. | ||
if (name === 'input' && ( | ||
type === 'select' || | ||
type === 'input' && /rad|check/.test(props.type) |
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.
🤔 are props
defined in here? Couldn't find them. Maybe I'm missing something.
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 think we need to differentiate vnode.type
and the input type which is usually in props.type
here. As far as I can tell both are needed to pass this check. So we'd need to pass props
through the arguments.
// Fix onInput not firing on select/radio/checkbox in Edge <= 18. | ||
if (name === 'input' && ( | ||
type === 'select' || | ||
type === 'input' && /rad|check/.test(props.type) |
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.
type === 'input' && /rad|check/.test(props.type) | |
type === 'input' && /rad|check/.test(type) |
I guess @cristianbote is right here :)
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 thinking this is what @developit wanted but, since the first condition checks that type
is strictly equal to 'input' the next condition will never be true, isn't it? Cause that'll end-up with /rad|check/.test('input')
which is not true.
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.
the type
in scope right now is the vnode type (html tag / component)
we need props.type
which is the type of the input
<input type="radio">
----- -----
| |
| props.type
vnode.type
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, that means that value
should be there instead.
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.
if you're talking about the value
in scope, no
that's the event listener function
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.
You are right, I've added a solution below.
if (name === 'input' && ( | ||
type === 'select' || | ||
type === 'input' && /rad|check/.test(props.type) |
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.
if (name === 'input' && ( | |
type === 'select' || | |
type === 'input' && /rad|check/.test(props.type) | |
if ((name === 'input' || /rad|check/.test(name)) && | |
(type === 'select' || type === 'input') |
This one makes the tests to pass for radio and checkboxes as well. Is this what you had in mind @developit? 😄
Alternative solution. There are a few properties that exist on
<select>
elements but not other inputs. This isn't ideal from a performance perspective, but the check only runs ononInput
handlers, so the impact should be minimal. Alternatively, we could plumbvnode
through prop diffing functions and checkvnode.type
.Properties audit: