Skip to content

Commit

Permalink
Focus on TOC when TOC is opened
Browse files Browse the repository at this point in the history
For: openstax/unified#2711
Also added an aria-label to HighlightsHelpInfo close button
  • Loading branch information
RoyEJohnson committed Jan 5, 2024
1 parent 8935795 commit 1838b76
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/app/content/components/SidebarControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const CloseToCAndMobileMenuButton = styled((props) => {
`;

// tslint:disable-next-line:variable-name
export const TOCControl = ({ message, children, ...props }: React.PropsWithChildren<InnerProps>) =>
const TOCControl = ({ message, children, ...props }: React.PropsWithChildren<InnerProps>) =>
<OpenButton
aria-label={useIntl().formatMessage({ id: message })}
{...props}
Expand Down
7 changes: 7 additions & 0 deletions src/app/content/components/TableOfContents/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ export class TableOfContents extends Component<SidebarProps> {
expandCurrentChapter(this.activeSection.current);
this.scrollToSelectedPage();
}
if (this.props.isOpen && !prevProps.isOpen) {
const firstItemInToc = this.sidebar.current?.querySelector(
'ol > li a,old > li summary'
) as HTMLElement;

firstItemInToc?.focus();
}
}

public componentWillUnmount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const HighlightsHelpInfo = () => {

return <Wrapper data-analytics-region='Mobile MH help info'>
<Message />
<PlainButton onClick={dismiss} data-analytics-label='close'>
<PlainButton onClick={dismiss} data-analytics-label='close' aria-label='dismiss'>
<CloseIcon />
</PlainButton>
</Wrapper>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ exports[`HighlightsHelpInfo matches snapshot when showed 1`] = `
}
/>
<button
aria-label="dismiss"
className="c1"
data-analytics-label="close"
onClick={[Function]}
Expand Down

0 comments on commit 1838b76

Please sign in to comment.