Skip to content

Commit 2a1321b

Browse files
Add select divider support
1 parent 634f246 commit 2a1321b

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/__tests__/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ describe('Index', () => {
111111
'Row',
112112
'SearchIcon',
113113
'Select',
114+
'SelectDivider',
114115
'SelectOption',
115116
'SkipLink',
116117
'SummaryList',

src/components/form-elements/select/Select.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

33
import classNames from 'classnames';
4-
import { forwardRef, type ComponentPropsWithoutRef } from 'react';
4+
import { forwardRef, type ComponentPropsWithoutRef, type FC } from 'react';
55

66
import { FormGroup } from '#components/utils/index.js';
77
import { type FormElementProps } from '#util/types/FormTypes.js';
@@ -27,13 +27,17 @@ const SelectComponent = forwardRef<HTMLSelectElement, SelectProps>(
2727
),
2828
);
2929

30+
export const SelectDivider: FC = () => <hr />;
31+
3032
export const SelectOption = forwardRef<HTMLOptionElement, ComponentPropsWithoutRef<'option'>>(
3133
(props, forwardedRef) => <option ref={forwardedRef} {...props} />,
3234
);
3335

3436
SelectComponent.displayName = 'Select';
37+
SelectDivider.displayName = 'Select.Divider';
3538
SelectOption.displayName = 'Select.Option';
3639

3740
export const Select = Object.assign(SelectComponent, {
41+
Divider: SelectDivider,
3842
Option: SelectOption,
3943
});

stories/Form Elements/Select.stories.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ export const SelectWithErrorAndHintText: Story = {
5858
},
5959
};
6060

61+
export const SelectWithDivider: Story = {
62+
render: (args) => (
63+
<Select {...args}>
64+
<Select.Option value="first-name-ascending">First name (A to Z)</Select.Option>
65+
<Select.Option value="first-name-descending">First name (Z to A)</Select.Option>
66+
<Select.Divider />
67+
<Select.Option value="last-name-ascending">Last name (A to Z)</Select.Option>
68+
<Select.Option value="last-name-descending">Last name (Z to A)</Select.Option>
69+
</Select>
70+
),
71+
};
72+
6173
export const SelectWithButton: Story = {
6274
args: {
6375
formGroupProps: {

0 commit comments

Comments
 (0)