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

Add native change event for hiddenSelect #6320

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gijsroge
Copy link

@gijsroge gijsroge commented May 2, 2024

Closes #6217

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

yarn jest packages/@react-aria/select/test/HiddenSelect.test.tsx -t "should trigger onChange"

🧢 Your Project:

@gijsroge gijsroge changed the title add native change event for hiddenSelect Add native change event for hiddenSelect May 2, 2024
Co-authored-by: Robert Snow <snowystinger@gmail.com>
Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

Looks like one of the Picker tests is failing. Have you looked into it?

@gijsroge
Copy link
Author

gijsroge commented May 3, 2024

Looks like one of the Picker tests is failing. Have you looked into it?

Will look into it this weekend yeah.

@gijsroge
Copy link
Author

gijsroge commented May 5, 2024

Been struggling to find out why this line causes that Picker test to fail:

selectRef.current.dispatchEvent(new Event('change', {bubbles: true}));

I've added a story in the Picker story where you can debug the test. I cannot reproduce it manually. Will do another attempt later on.

Another thing i've realised is that in the HiddenSelect there will rendered a hidden input instead of a Native Select if there are more then 300 options. Will still have to cover this as well.

if (state.collection.size <= 300) {
return (
<div {...containerProps} data-testid="hidden-select-container">
<input {...inputProps} />
<label>
{label}
<select {...selectProps} ref={selectRef}>
<option />
{[...state.collection.getKeys()].map(key => {
let item = state.collection.getItem(key);
if (item.type === 'item') {
return (
<option
key={item.key}
value={item.key}>
{item.textValue}
</option>
);
}
})}
</select>
</label>
</div>
);
} else if (name) {
return (
<input
type="hidden"
autoComplete={selectProps.autoComplete}
name={name}
disabled={isDisabled}
value={state.selectedKey ?? ''} />
);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Select does not propagate change event
2 participants