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

[RAC] `Popover` style inside `Select` & `ComboBox` does not works properly

Open 6thpath opened this issue 1 year ago โ€ข 1 comments

Provide a general summary of the issue here

when using Select or ComboBox component, passing style as function to Popover component would make --trigger-width style property is unavailable

๐Ÿค” Expected Behavior?

Popover inside Select & ComboBox also receive --trigger-width even if style is specified as a function

๐Ÿ˜ฏ Current Behavior

--trigger-width is not passed to Popover when style is passed to component as a function

๐Ÿ’ Possible Solution

No response

๐Ÿ”ฆ Context

No response

๐Ÿ–ฅ๏ธ Steps to Reproduce

https://codesandbox.io/p/sandbox/racpopover-lfv6dt

try to comment the 33rd line and uncomment the 34th line. as you can see, whenever style prop is function then --trigger-width is not passed to the popover

Version

latest

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

No response

๐Ÿ•ท Tracking Issue

No response

6thpath avatar Apr 24 '24 09:04 6thpath

I did some digging, and it looks like the root cause of this is the fact that useContextProps() will merge contextProps and props only when both of them are of type object: https://github.com/adobe/react-spectrum/blob/a597a0ce5f345a7c5968939d120eafbe6f02ac2a/packages/react-aria-components/src/utils.tsx#L193-L204

Since the above condition is not met when a user provides their style as a function, it resorts to the default merging strategy of mergeProps(contextProps, props), which is to select the value of the last argument (in our case, props over contextProps: https://github.com/adobe/react-spectrum/blob/a597a0ce5f345a7c5968939d120eafbe6f02ac2a/packages/%40react-aria/utils/src/mergeProps.ts#L68-L70

So that's why the contextProps passed by Combobox that contains style: {'--trigger-width': menuWidth} is overwritten by the user provided style={() => ({ background: "red" })}.

sookmax avatar Apr 24 '24 13:04 sookmax