-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Focus element with accessible role when switching steps (#3235)
Co-authored-by: Johannes Weber <[email protected]>
- Loading branch information
1 parent
3146174
commit 0451d85
Showing
3 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
import InternalHeader from '../../../lib/components/header/internal'; | ||
import createWrapper from '../../../lib/components/test-utils/dom'; | ||
|
||
describe('InternalHeader', () => { | ||
test('tabindex attribute is not set when not provided', () => { | ||
render(<InternalHeader variant="h3">h3 title</InternalHeader>); | ||
const headerElement = createWrapper().find('h3')!.getElement(); | ||
expect(headerElement).not.toHaveAttribute('tabindex'); | ||
}); | ||
|
||
test('heading tag is focusable via ref', () => { | ||
const ref = React.createRef<HTMLHeadingElement>(); | ||
render( | ||
<InternalHeader variant="h3" __headingTagTabIndex={-1} __headingTagRef={ref}> | ||
h3 title | ||
</InternalHeader> | ||
); | ||
const headerElement = createWrapper().find('h3')!.getElement(); | ||
expect(headerElement).toHaveTextContent('h3 title'); | ||
expect(headerElement).toHaveAttribute('tabindex', '-1'); | ||
expect(document.activeElement).not.toBe(headerElement); | ||
ref.current?.focus(); | ||
expect(document.activeElement).toBe(headerElement); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters