react-spectrum icon indicating copy to clipboard operation
react-spectrum copied to clipboard

Select does not propagate change event

Open gijsroge opened this issue 1 year ago โ€ข 2 comments

Provide a general summary of the issue here

When you change a value in a Select element there is no change event that bubbles causing patterns like <form onChange> to stop working.

๐Ÿค” Expected Behavior?

The select should trigger a change event like normal form elements.

๐Ÿ˜ฏ Current Behavior

The <Select> element does not behave like a native <select> element by not bubbling change events.

๐Ÿ’ Possible Solution

I believe the reason why this currently does not work is because the select just get's re-rendered. Maybe adding a manual change event in the <HiddenSelect> would solve this.

๐Ÿ”ฆ Context

No response

๐Ÿ–ฅ๏ธ Steps to Reproduce

https://codesandbox.io/p/sandbox/twilight-voice-tjmwcl?file=%2Fsrc%2FApp.js%3A4%2C9

Version

1.0.0-rc.0

What browsers are you seeing the problem on?

Firefox, Chrome, Safari, Microsoft Edge

If other, please specify.

No response

What operating system are you using?

macOS

๐Ÿงข Your Company/Team

No response

๐Ÿ•ท Tracking Issue

No response

gijsroge avatar Apr 17 '24 14:04 gijsroge

Thanks for the issue and initial digging, I think your solution could work.

snowystinger avatar Apr 17 '24 20:04 snowystinger

@snowystinger i've already patched this in my project, I could start a PR if you want.

gijsroge avatar Apr 17 '24 20:04 gijsroge

We are having the same issue with other form elements including Checkbox, Combobox and RadioGroup. Not sure if this has the same root cause or is a separate issue.

joshuajaco avatar Jul 01 '24 08:07 joshuajaco

This one also seems to be the same issue: https://github.com/adobe/react-spectrum/issues/5955

joshuajaco avatar Jul 01 '24 11:07 joshuajaco

After some testing I think the proposed solution will only work for components using a hidden <select> element. React does not bind onChange to any native event directly for <input> elements, see: https://github.com/facebook/react/issues/19846#issuecomment-694241217.

I tested workaround/solutions from the following issues without success (using react through next.js):

  • https://github.com/facebook/react/issues/19846
  • https://github.com/facebook/react/issues/11488
  • https://github.com/facebook/react/issues/10135
  • https://github.com/facebook/react/issues/11095
  • https://github.com/facebook/react/issues/10135
  • https://github.com/facebook/react/issues/1152

joshuajaco avatar Jul 02 '24 12:07 joshuajaco

Checkbox/Radio is probably a different issue, looks like we stop propagation on both of those, https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/toggle/src/useToggle.ts#L56

snowystinger avatar Jul 02 '24 23:07 snowystinger

Hey!

I wanted to add that my team is also experiencing this issue. As a temporary measure, we have "hacked" a workaround in our codebase that submits a native onChange event. However, we are looking forward to a more permanent fix. It seems like we are experiencing similar issues with our checkboxes but I will do some extra research into them to make sure it is not a bug on our side.

Could you provide an update on the status of this issue? Thanks in advance ๐Ÿ˜ƒ

RickHuizing01 avatar Jul 24 '24 09:07 RickHuizing01