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

[ FEATURE ] Select Auto Width #301

Open
leifdejong opened this issue Jan 7, 2025 · 1 comment
Open

[ FEATURE ] Select Auto Width #301

leifdejong opened this issue Jan 7, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@leifdejong
Copy link

Is your feature request related to a problem? Please describe.
Not so much a problem but the fact that the SelectContent width doesn't inherit the SelectTrigger width. Would be nice to have this automated.

Describe the solution you'd like
I was thinking that there should be a way to capture the SelectTrigger layout width and have an option for SelectContent to inherit that width. In the primitive, we could use the rootContext to store the trigger layout and then have content set the width style if the user specifies some autoWidth property on content.

Describe alternatives you've considered
Manually specifying the width as per the example but that is not great with different screen widths as the input component's width could change depending on the screen.

Additional context
How I solved it in a higher order component:

  const [triggerWidth, setTriggerWidth] = useState(0);

  const handleTriggerLayout = (event: LayoutChangeEvent) => {
    const { width } = event.nativeEvent.layout;
    setTriggerWidth(width);
  };
  
  return (
    <Select>
      <SelectTrigger onLayout={handleTriggerLayout}>
        <SelectValue />
      </SelectTrigger>
      <SelectContent} style={{ width: triggerWidth }}>
        ...
      </SelectContent>
    </Select>
    );
@leifdejong leifdejong added the enhancement New feature or request label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants
@leifdejong and others