-
-
Notifications
You must be signed in to change notification settings - Fork 303
feat: introduce ClickableRegion component to improve keyboard accessibility for interaction editors #6094
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
feat: introduce ClickableRegion component to improve keyboard accessibility for interaction editors #6094
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { render, screen, fireEvent } from '@testing-library/vue'; | ||
| import VueRouter from 'vue-router'; | ||
| import ClickableRegion from '../index.vue'; | ||
|
|
||
| describe('ClickableRegion', () => { | ||
| it('renders a button with the given aria-label', () => { | ||
| render(ClickableRegion, { | ||
| props: { | ||
| ariaLabel: 'Test label', | ||
| }, | ||
| routes: new VueRouter(), | ||
| }); | ||
|
|
||
| expect(screen.getByRole('button', { name: 'Test label' })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('does not render the button when suppressed is true', () => { | ||
| render(ClickableRegion, { | ||
| props: { | ||
| ariaLabel: 'Test label', | ||
| suppressed: true, | ||
| }, | ||
| routes: new VueRouter(), | ||
| }); | ||
|
|
||
| expect(screen.queryByRole('button')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('emits a single click event on mouse click', async () => { | ||
| const { emitted } = render(ClickableRegion, { | ||
| props: { | ||
| ariaLabel: 'Test label', | ||
| }, | ||
| routes: new VueRouter(), | ||
| }); | ||
|
|
||
| await fireEvent.click(screen.getByRole('button')); | ||
|
|
||
| expect(emitted().click).toHaveLength(1); | ||
| }); | ||
|
|
||
| it('emits a single click event on Enter key', async () => { | ||
| const { emitted } = render(ClickableRegion, { | ||
| props: { | ||
| ariaLabel: 'Test label', | ||
| }, | ||
| routes: new VueRouter(), | ||
| }); | ||
|
|
||
| const button = screen.getByRole('button'); | ||
| await fireEvent.click(button); | ||
|
|
||
| expect(emitted().click).toHaveLength(1); | ||
| }); | ||
|
|
||
| it('emits a single click event on Space key', async () => { | ||
| const { emitted } = render(ClickableRegion, { | ||
| props: { | ||
| ariaLabel: 'Test label', | ||
| }, | ||
| routes: new VueRouter(), | ||
| }); | ||
|
|
||
| const button = screen.getByRole('button'); | ||
| await fireEvent.click(button); | ||
|
|
||
| expect(emitted().click).toHaveLength(1); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| <template> | ||
|
|
||
| <!-- | ||
| a11y: Outer div catches mouse clicks. | ||
| Keyboard a11y is handled by the hidden button overlay below. | ||
| --> | ||
| <div | ||
| class="clickable-area" | ||
| @click="onClick" | ||
|
Member
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. Just saw that this is similar to how we handle our |
||
| > | ||
| <button | ||
|
AlexVelezLl marked this conversation as resolved.
|
||
| v-if="!suppressed" | ||
| type="button" | ||
| class="overlay-button" | ||
|
AlexVelezLl marked this conversation as resolved.
|
||
| :aria-label="ariaLabel" | ||
| @click.stop="onClick" | ||
| ></button> | ||
| <div class="content-wrapper"> | ||
| <slot></slot> | ||
| </div> | ||
| </div> | ||
|
|
||
| </template> | ||
|
|
||
|
|
||
| <script> | ||
|
|
||
| export default { | ||
| name: 'ClickableRegion', | ||
| setup(props, { emit }) { | ||
| function onClick(event) { | ||
| if (props.suppressed) return; | ||
| if (event && event.stopPropagation) { | ||
| event.stopPropagation(); | ||
| } | ||
| emit('click', event); | ||
| } | ||
| return { onClick }; | ||
| }, | ||
| props: { | ||
| ariaLabel: { | ||
| type: String, | ||
| required: true, | ||
| }, | ||
| suppressed: { | ||
| type: Boolean, | ||
| default: false, | ||
| }, | ||
| }, | ||
| emits: ['click'], | ||
| }; | ||
|
|
||
| </script> | ||
|
|
||
|
|
||
| <style lang="scss" scoped> | ||
|
|
||
| .clickable-area { | ||
| position: relative; | ||
| border-radius: inherit; | ||
| } | ||
|
|
||
| .overlay-button { | ||
| position: absolute; | ||
| top: 0; | ||
| left: 0; | ||
| z-index: 0; | ||
| width: 100%; | ||
| height: 100%; | ||
| padding: 0; | ||
| margin: 0; | ||
| cursor: pointer; | ||
| background: transparent; | ||
| border: 0; | ||
| border-radius: inherit; | ||
| outline: none; | ||
|
|
||
| &:hover { | ||
| background-color: v-bind('$themeTokens.fineLine'); | ||
| } | ||
|
|
||
| &:focus-visible { | ||
| outline: 2px solid v-bind('$themeTokens.focusOutline'); | ||
| outline-offset: 2px; | ||
| } | ||
| } | ||
|
|
||
| .content-wrapper { | ||
| position: relative; | ||
| z-index: 1; | ||
| } | ||
|
|
||
| </style> | ||
Uh oh!
There was an error while loading. Please reload this page.