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

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

Open
6thpath opened this issue Apr 24, 2024 · 1 comment
Open

Comments

@6thpath
Copy link

6thpath commented Apr 24, 2024

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 6thpath changed the title RAC Popover width RAC Popover style inside Select & ComboBox does not works properly Apr 24, 2024
@6thpath 6thpath changed the title RAC Popover style inside Select & ComboBox does not works properly [RAC] Popover style inside Select & ComboBox does not works properly Apr 24, 2024
@sookmax
Copy link
Contributor

sookmax commented Apr 24, 2024

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:

// mergeProps does not merge `style`. Adding this there might be a breaking change.
if (
'style' in contextProps &&
contextProps.style &&
typeof contextProps.style === 'object' &&
'style' in props &&
props.style &&
typeof props.style === 'object'
) {
// @ts-ignore
mergedProps.style = {...contextProps.style, ...props.style};
}

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:

} else {
result[key] = b !== undefined ? b : a;
}

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

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

No branches or pull requests

2 participants