Skip to content

Commit a9ac08a

Browse files
committed
feat: add option for select trigger to be full width [LW-9231]
1 parent 674f6a6 commit a9ac08a

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

src/design-system/select/select-root.component.css.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,7 @@ export const content = styleVariants({
117117
},
118118
],
119119
});
120+
121+
export const triggerFullWidth = sx({
122+
width: '$fill',
123+
});

src/design-system/select/select-root.component.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React from 'react';
33

44
import ChevronDownIcon from '@icons/ChevronDownComponent';
55
import * as Select from '@radix-ui/react-select';
6+
import cn from 'classnames';
67

78
import { Item, ItemRoot } from './select-item';
89
import * as cx from './select-root.component.css';
@@ -24,6 +25,7 @@ export type SelectRootProps = Pick<
2425
value: string | undefined;
2526
variant?: SelectVariant;
2627
portalContainer?: HTMLElement;
28+
triggerFullWidth?: boolean;
2729
triggerTestId?: string;
2830
zIndex?: number;
2931
};
@@ -54,6 +56,7 @@ const isValidSelectRootChild = (
5456
* @param showArrow Render arrow icon next to the input value, when the Select is closed.
5557
* @param value See: https://www.radix-ui.com/primitives/docs/components/select#root
5658
* @param variant The style variant.
59+
* @param triggerFullWidth Make the Select trigger element span the full width of its parent element
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 />`.
5962
*/
@@ -71,6 +74,7 @@ export const Root = ({
7174
showArrow = false,
7275
value,
7376
variant = 'plain',
77+
triggerFullWidth,
7478
triggerTestId,
7579
zIndex,
7680
}: Readonly<SelectRootProps>): JSX.Element => {
@@ -87,7 +91,10 @@ export const Root = ({
8791
onValueChange={onChange}
8892
>
8993
<Select.Trigger
90-
className={cx.trigger[variant]}
94+
className={cn(
95+
cx.trigger[variant],
96+
triggerFullWidth ? cx.triggerFullWidth : null,
97+
)}
9198
id={id}
9299
data-testid={triggerTestId}
93100
>

src/design-system/select/select.stories.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,43 @@ const SelectAlignment = (): JSX.Element => (
7777
</Section>
7878
);
7979

80+
const SelectTriggerWidth = (): JSX.Element => (
81+
<Section
82+
title="Trigger Width"
83+
subtitle="The trigger element acts like an inline element (default) or can be set to span the full width of its parent element."
84+
>
85+
<Variants.Table
86+
headers={[
87+
'Trigger as inline element (default)',
88+
'Trigger with full width',
89+
]}
90+
>
91+
<Variants.Row>
92+
{[undefined, true].map(triggerFullWidth => (
93+
<Variants.Cell key={`triggerFullWidth-${triggerFullWidth}`}>
94+
<Select.Root
95+
triggerFullWidth={triggerFullWidth}
96+
variant="outline"
97+
value={options[2].value}
98+
onChange={(): void => void 0}
99+
placeholder={placeholder}
100+
showArrow
101+
>
102+
{options.map(option => (
103+
<Select.Item
104+
key={option.value}
105+
value={option.value}
106+
title={option.label}
107+
/>
108+
))}
109+
</Select.Root>
110+
</Variants.Cell>
111+
))}
112+
</Variants.Row>
113+
</Variants.Table>
114+
</Section>
115+
);
116+
80117
const SelectVariants = (): JSX.Element => {
81118
const { darkThemePortalContainer, lightThemePortalContainer } =
82119
usePortalContainer();
@@ -280,6 +317,8 @@ export const Overview = (): JSX.Element => (
280317
<Cell>
281318
<SelectAlignment />
282319
<Divider my="$64" />
320+
<SelectTriggerWidth />
321+
<Divider my="$64" />
283322
<SelectVariants />
284323
<Divider my="$64" />
285324
<SelectRootVariants />

0 commit comments

Comments
 (0)