@@ -3,6 +3,7 @@ import React from 'react';
33
44import ChevronDownIcon from '@icons/ChevronDownComponent' ;
55import * as Select from '@radix-ui/react-select' ;
6+ import cn from 'classnames' ;
67
78import { Item , ItemRoot } from './select-item' ;
89import * as cx from './select-root.component.css' ;
@@ -26,6 +27,8 @@ export type SelectRootProps = Pick<
2627 portalContainer ?: HTMLElement ;
2728 triggerTestId ?: string ;
2829 zIndex ?: number ;
30+ fullWidth ?: boolean ;
31+ className ?: string ;
2932} ;
3033
3134const isValidSelectRootChild = (
@@ -56,6 +59,8 @@ const isValidSelectRootChild = (
5659 * @param variant The style variant.
5760 * @param triggerTestId The `data-testid` attribute, passed to the input trigger / root element.
5861 * @param zIndex The `z-index` applied to the `<Select.Content />`.
62+ * @param fullWidth If `true`, the select trigger and content will take the full width of the parent container.
63+ * @param className The CSS class name applied to the root element.
5964 */
6065export const Root = ( {
6166 align = 'selected' ,
@@ -73,6 +78,8 @@ export const Root = ({
7378 variant = 'plain' ,
7479 triggerTestId,
7580 zIndex,
81+ fullWidth = false ,
82+ className,
7683} : Readonly < SelectRootProps > ) : JSX . Element => {
7784 const [ isOpen , setIsOpen ] = React . useState ( defaultOpen ) ;
7885
@@ -87,9 +94,10 @@ export const Root = ({
8794 onValueChange = { onChange }
8895 >
8996 < Select . Trigger
90- className = { cx . trigger [ variant ] }
9197 id = { id }
9298 data-testid = { triggerTestId }
99+ className = { cn ( cx . trigger [ variant ] , className ) }
100+ style = { fullWidth ? { width : '100%' } : undefined }
93101 >
94102 < Select . Value placeholder = { placeholder } />
95103 { showArrow && (
@@ -100,7 +108,12 @@ export const Root = ({
100108 </ Select . Trigger >
101109 < Select . Portal container = { portalContainer } >
102110 < Select . Content
103- style = { { zIndex } }
111+ style = { {
112+ zIndex,
113+ ...( fullWidth
114+ ? { width : 'var(--radix-select-trigger-width)' }
115+ : { } ) ,
116+ } }
104117 className = { cx . content [ variant ] }
105118 position = { align === 'selected' ? 'item-aligned' : 'popper' }
106119 >
0 commit comments