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

Button inside of Select open few popovers at the same time

Open dvasyliev opened this issue 1 year ago โ€ข 4 comments

Provide a general summary of the issue here

I need to have a contextual hint with a popover near the label for the select field. When I implement it and click on a hint button, I see 2 popovers opened, one for the hint, the second for select.

๐Ÿค” Expected Behavior?

  • When I click on a hint button, I see only a hint popover opened
  • The hint button has a different id from the select button
  • The hint button doesn't have aria-labeledby and aria-describedby attributes or have the correct ones (I'm not an expert in accessibility)

๐Ÿ˜ฏ Current Behavior

  • When I click on a hint button, I see 2 popovers opened, one for the hint, the second for select

  • The hint button has the same id as the select button

  • The hint button has wrong id's in the aria-labeledby and aria-describedby

  • The same behaviour I noticed for the DatePicker

  • Also when I use a hint with a DateField, after clicking on a hint button and closing a popover, the focus moves into DateField and I see the first segment active

๐Ÿ’ Possible Solution

Wrap Button for select and Popover into DialogTrigger, then the issue is gone, but the CSS variable var(--trigger-width) was reset for select Popover, and it has a bigger width than the select Button.

๐Ÿ”ฆ Context

I need to have a contextual hint with a popover near the label for the select field.

๐Ÿ–ฅ๏ธ Steps to Reproduce

I created the Select component following the example in the documentation of react-aria-components. Then added DialogTrigger with a Button and a Popover inside of the Label component.

Repo: https://github.com/dvasyliev/react-aria-components-popover-issue GitHub page with demo: https://dvasyliev.github.io/react-aria-components-popover-issue/?path=/story/selectwithhint--default

Version

[email protected]

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

MacOS

๐Ÿงข Your Company/Team

Doccle

๐Ÿ•ท Tracking Issue

No response

dvasyliev avatar Jan 31 '24 14:01 dvasyliev

The issue was gone when I used useButton hook from react-aria instead of Button component from react-aria-components. So the problem in the Button component. I use it as a temporary solution.

dvasyliev avatar Feb 01 '24 11:02 dvasyliev

See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label#interactive_content We are working as expected. Please move the button outside of the control.

snowystinger avatar Feb 01 '24 16:02 snowystinger

Even if I move it outside of label it has the same behaviour

dvasyliev avatar Feb 02 '24 08:02 dvasyliev

Ah, I see, I suspect that the context is leaking where it shouldn't. You could try clearing the context. See possible context values here https://react-spectrum.adobe.com/react-aria/Select.html#custom-children Should be able to just wrap your DialogTrigger in the same Provider from https://github.com/adobe/react-spectrum/blob/560f05005aa5dbc67f765573a52c5d4665b90f05/packages/react-aria-components/src/Select.tsx#L142 and pass it a blank values.

Let us know if that works

snowystinger avatar Feb 05 '24 20:02 snowystinger