Skip to content
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

[EuiInlineEdit] Final screen reader / a11y polish pass #6805

Merged
merged 6 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -667,9 +667,7 @@ exports[`EuiInlineEditForm Read Mode isReadOnly 1`] = `
<span
hidden=""
id="inlineEdit_generated-id"
>
Click to edit this text inline.
</span>
/>
</div>
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ exports[`EuiInlineEditText isReadOnly 1`] = `
<span
hidden=""
id="inlineEdit_generated-id"
>
Click to edit this text inline.
</span>
/>
</div>
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ exports[`EuiInlineEditTitle isReadOnly 1`] = `
>
<h1
class="euiTitle eui-textTruncate emotion-euiTitle-m"
role="presentation"
>
Hello World!
</h1>
Expand All @@ -30,9 +31,7 @@ exports[`EuiInlineEditTitle isReadOnly 1`] = `
<span
hidden=""
id="inlineEdit_generated-id"
>
Click to edit this text inline.
</span>
/>
</div>
`;

Expand Down
35 changes: 20 additions & 15 deletions src/components/inline_edit/inline_edit_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export const EuiInlineEditForm: FunctionComponent<EuiInlineEditFormProps> = ({
const editModeInputOnKeyDown = (event: KeyboardEvent<HTMLElement>) => {
switch (event.key) {
case keys.ENTER:
event.preventDefault(); // Enter keypresses will not proceed otherwise on webkit browsers & screen readers
saveInlineEditValue();
break;
case keys.ESCAPE:
Expand Down Expand Up @@ -249,14 +250,11 @@ export const EuiInlineEditForm: FunctionComponent<EuiInlineEditFormProps> = ({
)}
/>
</EuiFormRow>

<span id={editModeDescribedById} hidden>
{!isReadOnly && (
<EuiI18n
token="euiInlineEditForm.inputKeyboardInstructions"
default="Press Enter to save your edited text. Press Escape to cancel your edit."
/>
)}
<EuiI18n
token="euiInlineEditForm.inputKeyboardInstructions"
default="Press Enter to save your edited text. Press Escape to cancel your edit."
/>
</span>
</EuiFlexItem>

Expand Down Expand Up @@ -334,18 +332,25 @@ export const EuiInlineEditForm: FunctionComponent<EuiInlineEditFormProps> = ({
readModeDescribedById,
readModeProps?.['aria-describedby']
)}
onClick={(e: MouseEvent<HTMLButtonElement>) => {
activateEditMode();
readModeProps?.onClick?.(e);
}}
onClick={
// `undefined` prevents screen readers from announcing "clickable" when the button is readonly
!isReadOnly
? (e: MouseEvent<HTMLButtonElement>) => {
activateEditMode();
readModeProps?.onClick?.(e);
}
: undefined
}
>
{children(readModeValue)}
</EuiButtonEmpty>
<span id={readModeDescribedById} hidden>
<EuiI18n
token="euiInlineEditForm.activateEditModeDescription"
default="Click to edit this text inline."
/>
{!isReadOnly && (
<EuiI18n
token="euiInlineEditForm.activateEditModeDescription"
default="Click to edit this text inline."
/>
)}
</span>
</>
);
Expand Down
4 changes: 3 additions & 1 deletion src/components/inline_edit/inline_edit_title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ export const EuiInlineEditTitle: FunctionComponent<EuiInlineEditTitleProps> = ({
>
{(titleReadModeValue) => (
<EuiTitle size={size} className="eui-textTruncate">
<H>{titleReadModeValue}</H>
<H role={isReadOnly ? 'presentation' : undefined}>
{titleReadModeValue}
</H>
</EuiTitle>
)}
</EuiInlineEditForm>
Expand Down