File tree 5 files changed +241
-141
lines changed
5 files changed +241
-141
lines changed Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+
3
+ export default function announcePageTitle ( title : string ) {
4
+ const el = document . getElementById ( 'page-title-confirmation' ) ;
5
+
6
+ el ?. dispatchEvent ( new window . CustomEvent ( 'page-title' , {
7
+ detail : title
8
+ } ) ) ;
9
+ }
10
+
11
+ export function PageTitleConfirmation ( ) {
12
+ const [ docTitle , setDocTitle ] = React . useState ( '' ) ;
13
+ const ref = React . useRef ( null ) ;
14
+
15
+ React . useEffect (
16
+ ( ) => {
17
+ const el = ref . current as unknown as Element ; // it's not null
18
+ const listener = ( ( e : CustomEvent ) => {
19
+ setDocTitle ( e . detail ) ;
20
+ } ) as EventListener ;
21
+
22
+ el . addEventListener ( 'page-title' , listener ) ;
23
+ return ( ) => el . removeEventListener ( 'page-title' , listener ) ;
24
+ } ,
25
+ [ ]
26
+ ) ;
27
+
28
+ return (
29
+ < div id = "page-title-confirmation" ref = { ref } className = "sr-only" aria-live = "polite" >
30
+ { `Loaded page "${ docTitle } "` }
31
+ </ div >
32
+ ) ;
33
+ }
Original file line number Diff line number Diff line change @@ -3,16 +3,15 @@ import JITLoad from '~/helpers/jit-load';
3
3
import { useStickyData } from '../shared.js' ;
4
4
import Menus from './menus/menus' ;
5
5
import $ from '~/helpers/$' ;
6
+ import { PageTitleConfirmation } from './announce-page-title' ;
6
7
import './header.scss' ;
7
8
8
9
function doSkipToContent ( event ) {
9
10
event . preventDefault ( ) ;
10
11
const mainEl = document . getElementById ( 'main' ) ;
11
- const focusableItems = Array . from ( mainEl . querySelectorAll ( $ . focusable ) ) ;
12
-
13
- if ( focusableItems . length > 0 ) {
14
- const target = focusableItems [ 0 ] ;
12
+ const target = mainEl . querySelector ( $ . focusable ) ;
15
13
14
+ if ( target ) {
16
15
$ . scrollTo ( target ) ;
17
16
target . focus ( ) ;
18
17
}
@@ -24,12 +23,14 @@ function SkipToContent() {
24
23
) ;
25
24
}
26
25
26
+
27
27
export default function Header ( ) {
28
28
const stickyData = useStickyData ( ) ;
29
29
30
30
return (
31
31
< div className = "page-header" >
32
32
< SkipToContent />
33
+ < PageTitleConfirmation />
33
34
< JITLoad importFn = { ( ) => import ( './sticky-note/sticky-note.js' ) } stickyData = { stickyData } />
34
35
< Menus />
35
36
</ div >
Original file line number Diff line number Diff line change 3
3
export function useToggle (
4
4
initialState ?: boolean
5
5
) : [ boolean , ( state ?: boolean ) => boolean ] ;
6
+
7
+ export function htmlToText (
8
+ html : string
9
+ ) : string ;
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments