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

fix: accessibility issue in tabs #1184

Conversation

shrilakshmishastry
Copy link
Contributor

Issue:

Issues noticed:

  • Not highlighting the tab when the file name is focused
  • Not highlighting the focus state of the editor
  • cross icon or close button not keyboard accessible

Fixed:

  • basic tab accessibility pattern :

    1. on the tab click to focus on the first tab item initially and on the previously focused tab in case it's accessed earlier
    2. Managing Focus Within Components Using a Roving tabindex
    3. highlighting the focus on the tab and editor by default outline of the browser when focused
  • on the focus of the tab, close CTA is visible and is keyboard accessible

Screen recording

Tab pattern implementation
https://github.com/user-attachments/assets/6221d6dd-1050-486c-adb6-9e2e6b1420f2

Editor accessibility
https://github.com/user-attachments/assets/7049baa6-762d-4015-85b6-21fd20a20f41

What kind of change does this pull request introduce?

  • Accessibility fix

Checklist

  • Documentation; N/A
  • Storybook (if applicable);
  • Tests;
  • Ready to be merged;

This fix partially #1173

Copy link

codesandbox bot commented Aug 23, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

vercel bot commented Aug 23, 2024

@shrilakshmishastry is attempting to deploy a commit to the CodeSandbox Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

codesandbox-ci bot commented Aug 23, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link

vercel bot commented Aug 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sandpack-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 4, 2024 7:54am

sandpack-react/package.json Outdated Show resolved Hide resolved
<div
aria-labelledby={`${activeFile}-tab`}
className={classNames("code-editor", [editorClassName])}
id={`${activeFile}-tab-panel`}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that a page can contain multiple Sandpack instances with similar content, this ID will not be unique to the page. Is there any reason why you need an ID here? There is an alternative to generate unique identifier inside Sandpack

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this ID is used inside the FileTabs component, to add the aria-controls attribute.

aria-controls={`${filePath}-tab-panel`}

is there a way I can get a unique ID and pass it between FileTabs and CodeEditor?

One way I am thinking is to add a unique id with activeFile , what's your opinion ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just introduced a new hook (useSandpackId) to your branch and I think you could use it to generate ids

sandpack-react/src/components/FileTabs/index.tsx Outdated Show resolved Hide resolved
@shrilakshmishastry
Copy link
Contributor Author

Hey @danilowoz 👋 Thanks for reviewing !! Did you get a chance to try it out ?
I am not satisfied with how I handled the outline when the tab and code editor are focused , using the default browser outline. Please suggest how to improve this.

@danilowoz
Copy link
Member

I'm a bit hesitant about adding a ring focus over the code editor, giving the following reasons:

  • There is already a visual focus indication in the component (active line), and I just improved to remove the style when there is no focus;
  • It might disturb the layout once the editor wasn't designed to contain borders except for the border that wrap everything
  • If your project really needs a more prominent focus indication, you can always implement it on your side by overwriting the default styles.

Let me know what you think :)

@shrilakshmishastry
Copy link
Contributor Author

I'm a bit hesitant about adding a ring focus over the code editor, giving the following reasons:

  • There is already a visual focus indication in the component (active line), and I just improved to remove the style when there is no focus;
  • It might disturb the layout once the editor wasn't designed to contain borders except for the border that wrap everything
  • If your project really needs a more prominent focus indication, you can always implement it on your side by overwriting the default styles.

Let me know what you think :)

Hey 👋 ,

  1. I tried focusing the editor using a tab but could not see the focus highlight on both dark and light modes.
  2. focusing is outline right, it's not going to affect any layout , correct me here please
  3. can you please explain to me the last point a bit more?

@shrilakshmishastry
Copy link
Contributor Author

feat: add unique id to each tab and tab panel for aria-* attributes

  1. I used useSandpackId() in this commit to generate unique values for the aria-labelledby and aria-controls attributes.

  2. added back outline to the editor on focus

    outline: "$colors$accent auto 1px",

Screenshot 2024-09-01 at 8 55 07 PM

@@ -27,6 +27,9 @@ export const editorClassName = css({
[`.${placeholderClassName}`]: {
padding: "$space$4 0",
},
"&:focus-within": {
outline: "$colors$accent auto 1px",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shrilakshmishastry, this can be implemented on your end, meaning inside the application that implements Sandpack, instead of adding a default style that might not be wanted by everyone. For a basic and generic experience, the editor already provides the necessary hint when it's focused, so I don't think adding such an opinionated style will be a good idea now.

For example, this can be added to your application:

.sp-code-editor:focus-within  {
  outline: 1px auto red;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, got it 👍 make sense, I will revert this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

danilowoz
danilowoz previously approved these changes Sep 3, 2024
@danilowoz
Copy link
Member

It looks good to me! But could you please check the Typescript job and fix the issues?

@shrilakshmishastry
Copy link
Contributor Author

In the refactor: make activeFileUniqueId as optional paramater in FileTabs commit,

  1. I have made activeFileUniqueId as optional. So it doesn't break the existing consumption
  2. fixed the ts type issue, it was due to not passing this prop in codeviewer component
  3. moved aria-* to div level in FIleTab, this is done as voice-over was not considering tab as in a series of tabs when it was added to button.

@danilowoz can you please re-review ?

@danilowoz danilowoz merged commit 98af978 into codesandbox:main Sep 4, 2024
8 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants