Skip to content

Commit

Permalink
better a11y docs
Browse files Browse the repository at this point in the history
  • Loading branch information
bigfishdesign13 committed Oct 17, 2023
1 parent 18ba341 commit 731a020
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 30 deletions.
9 changes: 7 additions & 2 deletions src/components/FeedbackBox/FeedbackBox.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ Within the `FeedbackBox` component, the radio input field is created from the DS
`TextInput` component. Each of these components has their own accessibility
features documented in their respective Storybook pages.

When the form is submitted, focus is set to the confirmation message or the
error message if an error occurs.
After the `FeedbackBox` form is submitted, focus is set to the confirmation
message or the error message if an error occurs. The `tabindex` for the focused
element is set to `"-1"`, allowing for programmatic focus to be set. After focus
is set programmatically, the user will be in control of focus and will not be
able to tab back to the confirmation message or error message after tabbing
away. This is standard accessibility behavior and the user should not expect to
be able to tab back to a non-interactive element.

Whereas the `FeedbackBox`'s primary button element is placed within the DOM
structure where it is rendered, the dialog DOM structure is appended to the end
Expand Down
5 changes: 4 additions & 1 deletion src/components/FeedbackBox/feedbackBoxChangelogData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export const changelogData: ChangelogData[] = [
version: "Prerelease",
type: "Update",
affects: ["Accessibility", "Styles"],
notes: ["Remove the underline on the component's `Privacy Policy` link."],
notes: [
"Remove the underline on the component's `Privacy Policy` link.",
"Updates `tabindex` value from 0 to -1. See Accessibility section for details.",
],
},
{
date: "2023-9-28",
Expand Down
67 changes: 40 additions & 27 deletions src/components/NewsletterSignup/NewsletterSignup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,27 @@ import { changelogData } from "./newsletterSignupChangelogData";

## Accessibility

The `NewsletterSignup` component is a complex component built from various Reservoir
DS and Chakra components.

The `title` prop of the `NewsletterSignup` component expects a `HTML Element` or a `React Component`. By default it renderes a `h2` tag but it is
the responsibility of the consuming app to pass the heading tag (`h*`) that aligns with the page structure and ensures accessibility.

Within the `NewsletterSignup` component, the DS `form` component wraps around two DS `FormField` components.
Those`FormField` components hold a DS `TextInput` component of `type="email"` and a DS `Button` component of `type="submit"` respectively.
Each of these components has their own accessibility features documented in their respective Storybook pages.

When the form is submitted, focus is set to the confirmation message or the
error message if an error occurs.
The `NewsletterSignup` component is a complex component built from various
Reservoir DS and Chakra components.

The `title` prop of the `NewsletterSignup` component expects a `HTML Element` or
a `React Component`. By default it renderes a `h2` tag but it is the
responsibility of the consuming app to pass the heading tag (`h*`) that aligns
with the page structure and ensures accessibility.

Within the `NewsletterSignup` component, the DS `form` component wraps around
two DS `FormField` components. Those`FormField` components hold a DS `TextInput`
component of `type="email"` and a DS `Button` component of `type="submit"`
respectively. Each of these components has their own accessibility features
documented in their respective Storybook pages.

After the `NewsletterSignup` form is submitted, focus is set to the confirmation
message or the error message if an error occurs. The `tabindex` for the focused
element is set to `"-1"`, allowing for programmatic focus to be set. After focus
is set programmatically, the user will be in control of focus and will not be
able to tab back to the confirmation message or error message after tabbing
away. This is standard accessibility behavior and the user should not expect to
be able to tab back to a non-interactive element.

Resources:

Expand All @@ -55,8 +64,9 @@ Resources:

## JSX Elements passed to descriptionText Prop

Alternatively to a `descriptionText` of type `string`, a HTML Element or React component can be passed. When passing a JSX Element, the consuming app is responsible
to assure its accessibility.
Alternatively to a `descriptionText` of type `string`, a HTML Element or React
component can be passed. When passing a JSX Element, the consuming app is
responsible to assure its accessibility.

_NOTE: This is applicable for all component props accepting HTML/JSX elements._

Expand All @@ -66,17 +76,17 @@ _NOTE: This is applicable for all component props accepting HTML/JSX elements._

Submitted form data can be retrieved when the `NewsletterSignup` component is
submitted through the required `onSubmit` prop. This prop expects a function and
it will be called when the form is submitted. Similar to other DS form-components
that have function props, the data from the component will be returned in the
function's argument. In this case, it will be a single object.
it will be called when the form is submitted. Similar to other DS
form-components that have function props, the data from the component will be
returned in the function's argument. In this case, it will be a single object.

The submitted form data will be passed as an object that the parent component
can use. The returned object will always contain the "email" field.

Below is an example callback function named `onSubmit` that is passed to the
`NewsletterSignup` component's `onSubmit` prop and how the view is controlled
in the data submission process. The form data will be returned through
the function's argument as an object, called `values` in the example below.
`NewsletterSignup` component's `onSubmit` prop and how the view is controlled in
the data submission process. The form data will be returned through the
function's argument as an object, called `values` in the example below.

<Source
code={`
Expand Down Expand Up @@ -113,15 +123,18 @@ language="jsx"

_NOTE: open the browser console to see the values logged in the example below._

The input value typed into the `TextInput` of the `NewsletterSignup` component can be accessed by the
functions passed to the `onChange` and `onSubmit` prop.
The input value typed into the `TextInput` of the `NewsletterSignup` component
can be accessed by the functions passed to the `onChange` and `onSubmit` prop.

Both the `onChange` and `onSubmit` callback functions can retrieved the submitted value as `event.target.email.value`
through the `event` object passed as the single argument.
Both the `onChange` and `onSubmit` callback functions can retrieved the
submitted value as `event.target.email.value` through the `event` object passed
as the single argument.

The following example logs the `event.target.email.value` to the console on each `onChange` call and upon
clicking the Submit button which triggers the `onSubmit` function and simulate a submission.
The component will transition through a `"submitting"` view to an alternating `"confirmation"`, `"error"` or "invalid Email" view.
The following example logs the `event.target.email.value` to the console on each
`onChange` call and upon clicking the Submit button which triggers the
`onSubmit` function and simulate a submission. The component will transition
through a `"submitting"` view to an alternating `"confirmation"`, `"error"` or
"invalid Email" view.

<Source
code={`
Expand Down

0 comments on commit 731a020

Please sign in to comment.