import type { Meta, StoryObj } from '@storybook/web-components-vite'; import { html } from 'lit'; import './index.ts'; import type { USASelect } from './usa-select.js'; const meta: Meta = { title: 'Forms/Select', component: 'usa-select', parameters: { layout: 'padded', docs: { description: { component: ` # USA Select The USA Select component provides accessible dropdown selection using official USWDS styling. This component wraps the standard HTML select element with USWDS classes and accessibility features. ## Features - Programmatic options or slotted content - Error and success states - Helper text and labels - Full accessibility support with ARIA attributes - Native form validation ## Usage Guidelines - Use sparingly (7-15 options) - Prefer radio buttons for fewer than 7 options - Use combo box for more than 15 options - Always include a label for accessibility - Provide a meaningful default option - Avoid auto-submission ## Accessibility - Labels are properly associated with selects - Error messages use role="alert" - Helper text connected via aria-describedby - Required fields clearly marked - Supports keyboard navigation `, }, }, }, argTypes: { label: { control: { type: 'text' }, description: 'Label text for the select', }, value: { control: { type: 'text' }, description: 'Selected value', }, hint: { control: { type: 'text' }, description: 'Helper text shown below the label', }, error: { control: { type: 'text' }, description: 'Error message text', }, success: { control: { type: 'text' }, description: 'Success state indicator', }, disabled: { control: { type: 'boolean' }, description: 'Whether the select is disabled', }, required: { control: { type: 'boolean' }, description: 'Whether the select is required', }, defaultOption: { control: { type: 'text' }, description: 'Default/placeholder option text', }, }, args: { label: 'Select label', value: '', hint: '', error: '', success: '', disabled: false, required: false, defaultOption: '- Select -', }, }; export default meta; type Story = StoryObj; export const Default: Story = { args: { label: 'Dropdown label', }, }; export const WithHelperText: Story = { args: { label: 'Select your state', hint: 'This is optional helper text', }, parameters: { docs: { description: { story: 'Select with helper text to provide additional context.', }, }, }, }; export const Required: Story = { args: { label: 'Required dropdown', hint: 'This field is required', required: true, }, parameters: { docs: { description: { story: 'Select marked as required with native browser validation.', }, }, }, }; export const WithError: Story = { args: { label: 'Dropdown with error', error: 'Please select a valid option', required: true, }, parameters: { docs: { description: { story: 'Select showing an error state with error message.', }, }, }, }; export const WithSuccess: Story = { args: { label: 'Dropdown with success', success: 'Great choice!', value: 'option2', }, parameters: { docs: { description: { story: 'Select showing a success state after valid selection.', }, }, }, }; export const Disabled: Story = { args: { label: 'Disabled dropdown', disabled: true, value: 'option1', }, parameters: { docs: { description: { story: 'Select in disabled state.', }, }, }, }; export const WithPreselected: Story = { args: { label: 'Preselected option', hint: 'An option has been pre-selected', value: 'option3', }, parameters: { docs: { description: { story: 'Select with a pre-selected value.', }, }, }, }; export const CustomDefaultOption: Story = { args: { label: 'Custom placeholder', defaultOption: 'Choose your option...', }, parameters: { docs: { description: { story: 'Select with custom placeholder/default option text.', }, }, }, }; export const FormIntegration: Story = { parameters: { controls: { disable: true }, docs: { description: { story: 'Select integrated within a form demonstrating validation and submission.', }, }, }, render: () => html`
`, }; export const InteractiveDemo: Story = { parameters: { controls: { disable: true }, docs: { description: { story: 'Interactive demonstration showing real-time selection changes and events.', }, }, }, render: () => html`

Selection Status:

No selection made
`, }; export const AccessibilityDemo: Story = { parameters: { controls: { disable: true }, docs: { description: { story: 'Demonstrates accessibility features including labels, ARIA attributes, and keyboard navigation.', }, }, }, render: () => html`

Accessibility Features

This select component includes:

  • Properly associated labels via the label element
  • Helper text linked with aria-describedby
  • Error messages with role="alert"
  • Required field indication
  • Full keyboard navigation support
Keyboard navigation:
  • Tab - Focus the select
  • Enter/Space - Open dropdown
  • Arrow keys - Navigate options
  • Enter - Select option
  • Esc - Close dropdown
`, }; export const CustomContent: Story = { parameters: { controls: { disable: true }, docs: { description: { story: 'Demonstrates using the default slot for custom content.', }, }, }, render: () => html`

This is custom slotted content.

Slots allow you to provide your own HTML content to the component.

`, };