@@ -6,7 +6,7 @@ import SegmentedControlIconButton from './SegmentedControlIconButton'
66import { ActionList } from '../ActionList'
77import { ActionMenu } from '../ActionMenu'
88import type { ResponsiveValue } from '../hooks/useResponsiveValue'
9- import { useResponsiveValue } from '../hooks/useResponsiveValue '
9+ import { getResponsiveAttributes } from '../internal/utils/getResponsiveAttributes '
1010import type { WidthOnlyViewportRangeKeys } from '../utils/types/ViewportRangeKeys'
1111import { isElement } from 'react-is'
1212import classes from './SegmentedControl.module.css'
@@ -45,8 +45,7 @@ const Root: React.FC<React.PropsWithChildren<SegmentedControlProps>> = ({
4545 React . Children . toArray ( children ) . some (
4646 child => React . isValidElement < SegmentedControlButtonProps > ( child ) && child . props . defaultSelected !== undefined ,
4747 )
48- const responsiveVariant = useResponsiveValue ( variant , 'default' )
49- const isFullWidth = useResponsiveValue ( fullWidth , false )
48+
5049 const selectedSegments = React . Children . toArray ( children ) . map (
5150 child =>
5251 React . isValidElement < SegmentedControlButtonProps | SegmentedControlIconButtonProps > ( child ) &&
@@ -110,9 +109,13 @@ const Root: React.FC<React.PropsWithChildren<SegmentedControlProps>> = ({
110109 )
111110 }
112111
113- return responsiveVariant === 'dropdown' ? (
114- // Render the 'dropdown' variant of the SegmentedControlButton or SegmentedControlIconButton
115- < >
112+ // Check if dropdown variant is used at any breakpoint
113+ const hasDropdownVariant =
114+ typeof variant === 'object' && variant !== null && Object . values ( variant ) . includes ( 'dropdown' )
115+
116+ // Render dropdown variant if needed
117+ const dropdownContent = hasDropdownVariant && (
118+ < div className = { classes . DropdownContainer } { ...getResponsiveAttributes ( 'variant' , variant ) } >
116119 < ActionMenu >
117120 { /*
118121 The aria-label is only provided as a backup when the designer or engineer neglects to show a label for the SegmentedControl.
@@ -150,15 +153,18 @@ const Root: React.FC<React.PropsWithChildren<SegmentedControlProps>> = ({
150153 </ ActionList >
151154 </ ActionMenu . Overlay >
152155 </ ActionMenu >
153- </ >
154- ) : (
155- // Render a segmented control
156+ </ div >
157+ )
158+
159+ // Render segmented control (default or hideLabels variant)
160+ const segmentedControlContent = (
156161 < ul
157162 aria-label = { ariaLabel }
158163 aria-labelledby = { ariaLabelledby }
159164 ref = { segmentedControlContainerRef }
160165 className = { clsx ( classes . SegmentedControl , className ) }
161- data-full-width = { isFullWidth || undefined }
166+ { ...getResponsiveAttributes ( 'full-width' , fullWidth ) }
167+ { ...getResponsiveAttributes ( 'variant' , variant ) }
162168 data-size = { size }
163169 { ...rest }
164170 >
@@ -186,43 +192,21 @@ const Root: React.FC<React.PropsWithChildren<SegmentedControlProps>> = ({
186192 } ,
187193 }
188194
189- // Render the 'hideLabels' variant of the SegmentedControlButton
190- if (
191- responsiveVariant === 'hideLabels' &&
192- React . isValidElement < SegmentedControlButtonProps > ( child ) &&
193- ( child . type === Button || isSlot ( child , Button ) )
194- ) {
195- const {
196- 'aria-label' : childAriaLabel ,
197- leadingVisual,
198- leadingIcon,
199- children : childPropsChildren ,
200- ...restChildProps
201- } = child . props
202- // Use leadingVisual if provided, otherwise fall back to leadingIcon
203- const visual = leadingVisual ?? leadingIcon
204- if ( ! visual ) {
205- // eslint-disable-next-line no-console
206- console . warn ( 'A `leadingVisual` or `leadingIcon` prop is required when hiding visible labels' )
207- } else {
208- return (
209- < SegmentedControlIconButton
210- aria-label = { childAriaLabel || childPropsChildren }
211- icon = { visual }
212- // Width is now handled by CSS: 32px default, 100% when data-full-width is set on parent
213- className = { classes . IconButton }
214- { ...sharedChildProps }
215- { ...restChildProps }
216- />
217- )
218- }
219- }
220-
221195 // Render the children as-is and add the shared child props
222196 return React . cloneElement ( child , sharedChildProps )
223197 } ) }
224198 </ ul >
225199 )
200+
201+ // Return both variants when dropdown is used, otherwise just the segmented control
202+ return hasDropdownVariant ? (
203+ < >
204+ { dropdownContent }
205+ { segmentedControlContent }
206+ </ >
207+ ) : (
208+ segmentedControlContent
209+ )
226210}
227211
228212Root . displayName = 'SegmentedControl'
0 commit comments