From 81859a1d9d648eab0792f4adfe42649a3062dc8d Mon Sep 17 00:00:00 2001 From: Lea Date: Wed, 20 Nov 2024 07:55:23 +0100 Subject: [PATCH] feat(styles): component form hint (#3961) Co-authored-by: Philipp Gfeller <1659006+gfellerph@users.noreply.github.com> --- .changeset/wild-bugs-work.md | 5 +++ .../components/dialog/dialog.stories.ts | 5 ++- .../components/forms/input/input.stories.ts | 3 +- .../components/forms/select/select.stories.ts | 5 ++- .../forms/slider/slider.snapshot.stories.ts | 1 + .../components/forms/slider/slider.stories.ts | 45 +++++++++---------- .../forms/textarea/textarea.stories.ts | 5 ++- .../foundation/icons/search-icons.blocks.tsx | 5 ++- .../src/stories/patterns/forms/forms.docs.mdx | 18 ++++---- .../stories/patterns/forms/forms.stories.ts | 7 ++- packages/styles/src/components/_index.scss | 1 + packages/styles/src/components/form-hint.scss | 16 +++++++ .../styles/src/components/form-range.scss | 2 +- .../styles/src/components/form-select.scss | 6 --- packages/styles/src/components/forms.scss | 14 +++--- .../styles/src/themes/bootstrap/_forms.scss | 1 - .../themes/bootstrap/forms/_form-text.scss | 2 - 17 files changed, 78 insertions(+), 63 deletions(-) create mode 100644 .changeset/wild-bugs-work.md create mode 100644 packages/styles/src/components/form-hint.scss delete mode 100644 packages/styles/src/themes/bootstrap/forms/_form-text.scss diff --git a/.changeset/wild-bugs-work.md b/.changeset/wild-bugs-work.md new file mode 100644 index 0000000000..a3a23a20bb --- /dev/null +++ b/.changeset/wild-bugs-work.md @@ -0,0 +1,5 @@ +--- +'@swisspost/design-system-styles': major +--- + +Changed the class name of assistive text below form fields from `.form-text` to `.form-hint` and improved accessibility by connecting the hint to the form through `aria-describedby`. diff --git a/packages/documentation/src/stories/components/dialog/dialog.stories.ts b/packages/documentation/src/stories/components/dialog/dialog.stories.ts index 24569321fe..8f21a73884 100644 --- a/packages/documentation/src/stories/components/dialog/dialog.stories.ts +++ b/packages/documentation/src/stories/components/dialog/dialog.stories.ts @@ -185,13 +185,14 @@ const FormTemplate = { type="text" placeholder="Placeholder" name="example-text-field" + aria-describedby="example-form-hint" required /> -
+

Hintus textus elare volare cantare hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis. -

+

diff --git a/packages/documentation/src/stories/components/forms/input/input.stories.ts b/packages/documentation/src/stories/components/forms/input/input.stories.ts index 173667c2e3..482cb53def 100644 --- a/packages/documentation/src/stories/components/forms/input/input.stories.ts +++ b/packages/documentation/src/stories/components/forms/input/input.stories.ts @@ -160,7 +160,7 @@ function render(args: Args, context: StoryContext) { const contextual: (TemplateResult | null)[] = [ args.validation === 'is-valid' ? html`

Ggranda sukceso!

` : null, args.validation === 'is-invalid' ? html`

Eraro okazis!

` : null, - args.hint !== '' ? html`
${args.hint}
` : null, + args.hint !== '' ? html`

${args.hint}

` : null, ]; const control: TemplateResult = html` @@ -172,6 +172,7 @@ function render(args: Args, context: StoryContext) { ?disabled="${args.disabled}" aria-label="${useAriaLabel ? args.label : nothing}" ?aria-invalid="${VALIDATION_STATE_MAP[args.validation]}" + aria-describedby="${args.hint !== '' ? 'form-hint-' + id : nothing}" value="${args.value ? args.value : nothing}" /> `; diff --git a/packages/documentation/src/stories/components/forms/select/select.stories.ts b/packages/documentation/src/stories/components/forms/select/select.stories.ts index aead5f98ae..d7bcf900c7 100644 --- a/packages/documentation/src/stories/components/forms/select/select.stories.ts +++ b/packages/documentation/src/stories/components/forms/select/select.stories.ts @@ -242,7 +242,9 @@ const Template: Story = { args.validation === 'is-invalid' ? html`

Eraro okazis!

` : null, - args.hint !== '' ? html`
${args.hint}
` : null, + args.hint !== '' + ? html`

${args.hint}

` + : null, ]; const control = html` - `, - ]; - } - - if (args.showValue === 'input') { return html`
${[label, control, ...contextual].filter(el => el !== null)}
-
${valueElement}
+
+ + +
`; - } else { - return html`${[label, control, valueElement, ...contextual].filter(el => el !== null)}`; + } else if (args.showValue === 'text') { + valueElement = html`

${args.value}

`; } + + return html`${[label, control, valueElement, ...contextual].filter(el => el !== null)}`; } export const Default: Story = {}; diff --git a/packages/documentation/src/stories/components/forms/textarea/textarea.stories.ts b/packages/documentation/src/stories/components/forms/textarea/textarea.stories.ts index d9e6521b8e..5db16960ff 100644 --- a/packages/documentation/src/stories/components/forms/textarea/textarea.stories.ts +++ b/packages/documentation/src/stories/components/forms/textarea/textarea.stories.ts @@ -194,7 +194,9 @@ function renderTextarea(args: Args, context: StoryContext) { args.validation === 'is-invalid' ? html`
Eraro okazis!
` : null, - args.hint !== '' ? html`
${args.hint}
` : null, + args.hint !== '' + ? html`

${args.hint}

` + : null, ]; const control = html` Reset Search ) : null} -
+

{`Showing ${this.state.icons.length} of ${report.icons.length} icons.`} -

+

diff --git a/packages/documentation/src/stories/patterns/forms/forms.docs.mdx b/packages/documentation/src/stories/patterns/forms/forms.docs.mdx index 422328226b..2dc4414f77 100644 --- a/packages/documentation/src/stories/patterns/forms/forms.docs.mdx +++ b/packages/documentation/src/stories/patterns/forms/forms.docs.mdx @@ -9,10 +9,7 @@ import * as FormPatternsStories from './forms.stories'; All things need to be contained inside a container. The container limits the size of the content and centers it on the page. -...`} - language="html" -/> +...`} language="html" /> ## Basic input @@ -24,6 +21,7 @@ next to the field. ## Vertical spacing + To add space between input, you can use [margin utilities](/?path=/docs/facaacfd-18f1-49b4-80f1-a96680730fa0--docs). @@ -74,13 +72,13 @@ Validation messages are placed directly after the `` (or after the `