Skip to content

Commit

Permalink
Select - expose description field (#431)
Browse files Browse the repository at this point in the history
* expose description field on select component

* add errorMessage to argTypes in storybook
  • Loading branch information
mkernohanbc authored Aug 8, 2024
1 parent 3a5219f commit b4a4487
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/react-components/src/components/Select/Select.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
color: var(--typography-color-disabled);
}

/* Rext description below select input */
.bcds-react-aria-Select--Description {
font: var(--typography-regular-small-body);
color: var(--typography-color-secondary);
padding: var(--layout-padding-xsmall) var(--layout-padding-none);
}

/* Error message */
.bcds-react-aria-Select--Error {
font: var(--typography-regular-small-body);
Expand Down
13 changes: 12 additions & 1 deletion packages/react-components/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export interface SelectProps<T extends object> extends ReactAriaSelectProps<T> {
placeholder?: string;
/** Defaults to `medium` */
size?: "small" | "medium";
/* Used for data validation and error handling */
/** Description or helper text that renders below the select input */
description?: string;
/** Used for data validation and error handling */
errorMessage?: string | ((validation: ValidationResult) => string);
}

Expand Down Expand Up @@ -113,6 +115,7 @@ export default function Select<T extends object>({
items,
sections,
label,
description,
placeholder,
size = "medium",
errorMessage,
Expand Down Expand Up @@ -143,6 +146,14 @@ export default function Select<T extends object>({
{isInvalid && iconError}
{isOpen ? <ChevronUp /> : <ChevronDown />}
</Button>
{description && (
<Text
slot="description"
className={`bcds-react-aria-Select--Description`}
>
{description}
</Text>
)}
<FieldError className="bcds-react-aria-Select--Error">
{errorMessage}
</FieldError>
Expand Down
10 changes: 10 additions & 0 deletions packages/react-components/src/stories/Select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,20 @@ const meta = {
control: { type: "text" },
description: "Text label that appears above the select button",
},
description: {
control: { type: "text" },
description:
"Additional description or helper text below the select button",
},
placeholder: {
control: { type: "text" },
description:
"Text label that appears inside the select input before an option has been selected",
},
errorMessage: {
control: { type: "text" },
description: "Text displayed when the input is invalid",
},
},
} satisfies Meta<typeof Select>;

Expand All @@ -55,6 +64,7 @@ export const SelectTemplate: Story = {
args: {
label: "Label",
size: "medium",
description: "Optional description or helper text",
isRequired: false,
isDisabled: false,
isInvalid: false,
Expand Down

0 comments on commit b4a4487

Please sign in to comment.