-
Notifications
You must be signed in to change notification settings - Fork 8
fix(search): wcag improvements #57 #431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9b2a87f
chore: fix search stories for better WCAG compliance #57
airikej cb20289
chore: search story cleanup #57
airikej ee57b31
Merge branch 'rc' into fix/57-search-wcag-react-issues
airikej aa4a066
fix(search): wcag improvements #57
airikej 75d089a
fix(search): fix stories ids for better accessibilty testing #57
airikej 3375c35
fix(search): update accessibility story description #57
airikej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,88 +31,89 @@ export default meta; | |
| type Story = StoryObj<SearchProps>; | ||
|
|
||
| const stateArray = ['Default', 'Hover', 'Focus', 'Active', 'Disabled']; | ||
| const sizeArray: SearchProps['size'][] = ['small', 'default', 'large']; | ||
|
|
||
| interface TemplateStateProps extends SearchProps { | ||
| array: typeof stateArray; | ||
| } | ||
|
|
||
| const sizeArray: SearchProps['size'][] = ['small', 'default', 'large']; | ||
|
|
||
| interface TemplateMultipleProps<Type = SearchProps['size']> extends SearchProps { | ||
| array: Type[]; | ||
| property: keyof SearchProps; | ||
| } | ||
|
|
||
| const TemplateColumn: StoryFn<TemplateMultipleProps> = (args) => { | ||
| const { array, property, ...textFieldProps } = args; | ||
| const { array, property, id = 'search', ...textFieldProps } = args; | ||
|
|
||
| return ( | ||
| <div className="example-list"> | ||
| {array.map((value, key) => ( | ||
| <Row className={`${key === array.length - 1 ? '' : 'border-bottom'} padding-14-16`} key={key}> | ||
| <Col width={2}> | ||
| <Text modifiers="bold">{value ? value.charAt(0).toUpperCase() + value.slice(1) : ''}</Text> | ||
| </Col> | ||
| <Col> | ||
| <VerticalSpacing> | ||
| <Search {...textFieldProps} {...{ [property]: value }} /> | ||
| <Search {...textFieldProps} button={{ icon: 'search', size: value }} {...{ [property]: value }} /> | ||
| <Search | ||
| {...textFieldProps} | ||
| button={{ iconLeft: 'search', children: 'Otsi', size: value }} | ||
| {...{ [property]: value }} | ||
| /> | ||
| </VerticalSpacing> | ||
| </Col> | ||
| </Row> | ||
| ))} | ||
| {array.map((value, key) => { | ||
| const baseId = `${id}-${property}-${value}`; | ||
|
|
||
| return ( | ||
| <Row className={`${key === array.length - 1 ? '' : 'border-bottom'} padding-14-16`} key={key}> | ||
| <Col width={2}> | ||
| <Text modifiers="bold">{value ? value.charAt(0).toUpperCase() + value.slice(1) : ''}</Text> | ||
| </Col> | ||
| <Col> | ||
| <VerticalSpacing> | ||
| <Search {...textFieldProps} {...{ [property]: value }} id={`${baseId}-plain`} /> | ||
| <Search | ||
| {...textFieldProps} | ||
| {...{ [property]: value }} | ||
| id={`${baseId}-icon`} | ||
| button={{ icon: 'search', size: value, 'aria-label': 'Search' }} | ||
| /> | ||
| <Search | ||
| {...textFieldProps} | ||
| {...{ [property]: value }} | ||
| id={`${baseId}-button`} | ||
| button={{ iconLeft: 'search', children: 'Search', size: value }} | ||
| /> | ||
| </VerticalSpacing> | ||
| </Col> | ||
| </Row> | ||
| ); | ||
| })} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| const TemplateColumnWithStates: StoryFn<TemplateStateProps> = (args) => { | ||
| const { array, ...textFieldProps } = args; | ||
| const { array, id = 'search', ...textFieldProps } = args; | ||
|
|
||
| return ( | ||
| <div className="state-example"> | ||
| {array.map((state, index) => ( | ||
| <Row key={index} className="padding-14-16"> | ||
| <Col lg={2} md={12} className="display-flex align-items-center"> | ||
| <Text modifiers="bold">{state}</Text> | ||
| </Col> | ||
| <Col lg={10} md={12} className="display-flex align-items-center"> | ||
| <Search disabled={state === 'Disabled'} {...textFieldProps} id={state} /> | ||
| </Col> | ||
| </Row> | ||
| ))} | ||
| {array.map((state, index) => { | ||
| const stateId = `${id}-${state.toLowerCase()}`; | ||
|
|
||
| return ( | ||
| <Row key={index} className="padding-14-16"> | ||
| <Col lg={2} md={12} className="display-flex align-items-center"> | ||
| <Text modifiers="bold">{state}</Text> | ||
| </Col> | ||
| <Col lg={10} md={12} className="display-flex align-items-center"> | ||
| <Search {...textFieldProps} id={stateId} disabled={state === 'Disabled'} /> | ||
| </Col> | ||
| </Row> | ||
| ); | ||
| })} | ||
|
|
||
| <Row className="padding-14-16"> | ||
| <Col width={2} className="display-flex align-items-center"> | ||
| <Text modifiers="bold">Success</Text> | ||
| </Col> | ||
| <Col className="display-flex align-items-center"> | ||
| <Search | ||
| {...textFieldProps} | ||
| id="success-search" | ||
| helper={{ | ||
| text: 'Feedback text', | ||
| type: 'valid', | ||
| }} | ||
| /> | ||
| <Search {...textFieldProps} id={`${id}-success`} helper={{ text: 'Feedback text', type: 'valid' }} /> | ||
| </Col> | ||
| </Row> | ||
|
|
||
| <Row className="padding-14-16"> | ||
| <Col width={2} className="display-flex align-items-center"> | ||
| <Text modifiers="bold">Error</Text> | ||
| </Col> | ||
| <Col className="display-flex align-items-center"> | ||
| <Search | ||
| {...textFieldProps} | ||
| id="error-search" | ||
| helper={{ | ||
| text: 'Feedback text', | ||
| type: 'error', | ||
| }} | ||
| /> | ||
| <Search {...textFieldProps} id={`${id}-error`} helper={{ text: 'Feedback text', type: 'error' }} /> | ||
| </Col> | ||
| </Row> | ||
| </div> | ||
|
|
@@ -121,16 +122,16 @@ const TemplateColumnWithStates: StoryFn<TemplateStateProps> = (args) => { | |
|
|
||
| export const Default: Story = { | ||
| args: { | ||
| id: 'example-1', | ||
| id: 'search-default', | ||
| label: 'Search', | ||
| placeholder: 'Search by name or keyword', | ||
| }, | ||
| }; | ||
|
|
||
| export const Sizes: StoryObj<TemplateMultipleProps> = { | ||
| render: TemplateColumn, | ||
|
|
||
| args: { | ||
| id: 'example-1', | ||
| id: 'search-sizes', | ||
| label: 'Search', | ||
| property: 'size', | ||
| array: sizeArray, | ||
|
|
@@ -142,6 +143,7 @@ export const States: StoryObj<TemplateStateProps> = { | |
| args: { | ||
| array: stateArray, | ||
| label: 'Search', | ||
| id: 'search-states', | ||
| }, | ||
| parameters: { | ||
| pseudo: { | ||
|
|
@@ -154,15 +156,15 @@ export const States: StoryObj<TemplateStateProps> = { | |
|
|
||
| export const Placeholder: Story = { | ||
| args: { | ||
| id: 'example-1', | ||
| id: 'search-placeholder', | ||
| label: 'Search', | ||
| placeholder: 'Name', | ||
| placeholder: 'Type something...', | ||
| }, | ||
| }; | ||
|
|
||
| export const Clearable: Story = { | ||
| args: { | ||
| id: 'example-1', | ||
| id: 'search-clearable', | ||
| label: 'Search', | ||
| isClearable: true, | ||
| value: 'Lorem ipsum', | ||
|
|
@@ -171,18 +173,55 @@ export const Clearable: Story = { | |
|
|
||
| export const ClearableButton: Story = { | ||
| args: { | ||
| id: 'example-1', | ||
| id: 'search-clearable-button', | ||
| label: 'Search', | ||
| isClearable: true, | ||
| value: 'Lorem ipsum', | ||
| button: { iconLeft: 'search', children: 'Otsi' }, | ||
| button: { iconLeft: 'search', children: 'Search' }, | ||
| }, | ||
| }; | ||
|
|
||
| export const WithHint: Story = { | ||
| args: { | ||
| id: 'example-1', | ||
| id: 'search-with-hint', | ||
| label: 'Search', | ||
| helper: { text: 'Hint text' }, | ||
| }, | ||
| }; | ||
|
|
||
| export const Estonian: Story = { | ||
| args: { | ||
| id: 'search-et', | ||
| label: 'Otsing', | ||
| placeholder: 'Otsi tooteid, artikleid või abiinfot...', | ||
| ariaLabel: 'Otsi kogu saidilt', | ||
| button: { iconLeft: 'search', children: 'Otsi' }, | ||
| }, | ||
| }; | ||
|
|
||
| export const AccessibilityFocused: Story = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would actually rather encourage to always use label element but add "sr-only" class when it must be visually hidden |
||
| name: 'Accessibility: No Visible Label', | ||
| args: { | ||
| id: 'search-accessible', | ||
| placeholder: 'Otsi tooteid või teenuseid...', | ||
| ariaLabel: 'Otsi tooteid või teenuseid', | ||
| }, | ||
| parameters: { | ||
| a11y: { | ||
| config: { | ||
| rules: { | ||
| label: { enabled: false }, | ||
| }, | ||
| }, | ||
| }, | ||
| docs: { | ||
| description: { | ||
| story: ` | ||
| Always prefer a native \`<label>\` element for form controls. | ||
| If the label must not be visible in the UI, hide it visually using an \`sr-only\` (or equivalent) class rather than removing it. This preserves correct semantics and provides the most reliable experience for screen reader users. | ||
| Use \`ariaLabel\` only as a fallback when a real \`<label>\` cannot be rendered. This follows WCAG 2.1 and EN 301 549 9.2.5.3. | ||
| `, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.