File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ export const MDXHeading = (props) => {
5
5
const { level, children, id } = props ;
6
6
7
7
return (
8
- < Heading level = { level } id = { id } >
8
+ < Heading level = { level } id = { id } tabIndex = { - 1 } >
9
9
{ /* Only output heading links for h2 and h3 \ */ }
10
10
{ level == 2 || level == 3 ? (
11
11
< Link href = { `#${ id } ` } > { children } </ Link >
Original file line number Diff line number Diff line change 1
1
import { render , screen } from '@testing-library/react' ;
2
2
import { MDXHeading } from '../MDXHeading' ;
3
+ import { TableOfContents } from '../../TableOfContents/index' ;
4
+ import userEvent from '@testing-library/user-event' ;
3
5
4
6
describe ( 'MDXHeading' , ( ) => {
5
7
it ( 'should render H2 with string and anchor link' , ( ) => {
@@ -53,4 +55,28 @@ describe('MDXHeading', () => {
53
55
expect ( heading ) . toHaveTextContent ( props . children ) ;
54
56
expect ( link ) . not . toBeInTheDocument ( ) ;
55
57
} ) ;
58
+
59
+ it ( 'should shift focus to in-content heading on TOC click' , async ( ) => {
60
+ const props = {
61
+ level : 2 ,
62
+ children : 'Test heading' ,
63
+ id : 'test-heading'
64
+ } ;
65
+ render ( < MDXHeading { ...props } /> ) ;
66
+
67
+ const heading = screen . queryByRole ( 'heading' , { level : 2 } ) ;
68
+ const tocHeadings = [
69
+ { linkText : 'Test heading' , hash : 'test-heading' , level : 'h2' }
70
+ ] ;
71
+
72
+ const tableOfContents = < TableOfContents headers = { tocHeadings } /> ;
73
+ render ( tableOfContents ) ;
74
+
75
+ const tocEntry = await screen . findByRole ( 'heading' , {
76
+ name : 'Test heading'
77
+ } ) ;
78
+
79
+ userEvent . click ( tocEntry ) ;
80
+ expect ( heading ) . toHaveFocus ( ) ;
81
+ } ) ;
56
82
} ) ;
Original file line number Diff line number Diff line change @@ -187,6 +187,12 @@ ol:not([class]) {
187
187
.amplify-heading--2 ,
188
188
.amplify-heading--3 {
189
189
scroll-margin-top : 9rem ;
190
+
191
+ & :focus-visible {
192
+ transition : none ;
193
+ outline : 2px solid var (--amplify-colors-border-focus );
194
+ outline-offset : 2px ;
195
+ }
190
196
}
191
197
}
192
198
You can’t perform that action at this time.
0 commit comments