-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
a11y-mobile-toc #8054
Open
katiegoines
wants to merge
13
commits into
main
Choose a base branch
from
a11y-mobile-toc-revive
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+155
−21
Open
a11y-mobile-toc #8054
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
11577aa
mobile toc styling
6487e5c
add mobile toc menu
2ec7b2e
toggle close on link click
7f43462
combine functions
0d95e7d
add type and moving empty div
ad67a12
fix toc behavior on desktop;
96ab617
Merge branch 'main' into a11y-mobile-toc
a4ed463
put desktop toc back in layout
99699f4
changes re: heather
1f681b0
responsiveness
29cbbe4
Merge branch 'main' into a11y-mobile-toc
cec18c7
fix extra toc
4a1b94b
fix merge conflict
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ import { | |
ALGOLIA_INDEX_NAME, | ||
ALGOLIA_APP_ID | ||
} from '../../constants/algolia'; | ||
import { IconMenu, IconDoubleChevron } from '@/components/Icons'; | ||
import { IconTOC, IconDoubleChevron } from '@/components/Icons'; | ||
import { Menu } from '@/components/Menu'; | ||
import { LayoutContext } from '@/components/Layout'; | ||
import { PlatformNavigator } from '@/components/PlatformNavigator'; | ||
|
@@ -19,23 +19,30 @@ import { PageLastUpdated } from '../PageLastUpdated'; | |
import Feedback from '../Feedback'; | ||
import RepoActions from '../Menu/RepoActions'; | ||
import { usePathWithoutHash } from '@/utils/usePathWithoutHash'; | ||
import { TableOfContents } from '../TableOfContents'; | ||
import { HeadingInterface } from '../TableOfContents/TableOfContents'; | ||
|
||
export const LayoutHeader = ({ | ||
currentPlatform, | ||
isGen1, | ||
pageType = 'inner', | ||
showLastUpdatedDate = true, | ||
showTOC | ||
showTOC, | ||
tocHeadings | ||
}: { | ||
currentPlatform: Platform; | ||
isGen1: boolean; | ||
pageType?: 'home' | 'inner'; | ||
showLastUpdatedDate: boolean; | ||
showTOC?: boolean; | ||
tocHeadings: HeadingInterface[]; | ||
}) => { | ||
const { menuOpen, toggleMenuOpen } = useContext(LayoutContext); | ||
const menuButtonRef = useRef<HTMLButtonElement>(null); | ||
const sidebarMenuButtonRef = useRef<HTMLButtonElement>(null); | ||
const { tocOpen, toggleTocOpen } = useContext(LayoutContext); | ||
const tocButtonRef = useRef<HTMLButtonElement>(null); | ||
const sidebarTocButtonRef = useRef<HTMLButtonElement>(null); | ||
const router = useRouter(); | ||
const asPathWithNoHash = usePathWithoutHash(); | ||
|
||
|
@@ -51,6 +58,18 @@ export const LayoutHeader = ({ | |
} | ||
}; | ||
|
||
const handleTocToggle = () => { | ||
if (!tocOpen) { | ||
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. |
||
toggleTocOpen(true); | ||
// For keyboard navigators, move focus to the close menu button in the nav | ||
setTimeout(() => sidebarTocButtonRef?.current?.focus(), 0); | ||
} else { | ||
toggleTocOpen(false); | ||
// For keyboard navigators, move focus back to menu button in header | ||
tocButtonRef?.current?.focus(); | ||
} | ||
}; | ||
|
||
// Search result transform function that will strip out the pageMain anchor tag | ||
// Algolia search results include the anchor tag where the content was found but since we | ||
// are aggregating records this ends up always being the pageMain anchor tag which is the | ||
|
@@ -74,9 +93,20 @@ export const LayoutHeader = ({ | |
ref={menuButtonRef} | ||
className="search-menu-toggle mobile-toggle" | ||
> | ||
<IconMenu aria-hidden="true" /> | ||
<IconTOC aria-hidden="true" /> | ||
Menu | ||
</Button> | ||
{showTOC ? ( | ||
<Button | ||
onClick={() => handleTocToggle()} | ||
size="small" | ||
ref={tocButtonRef} | ||
className="search-menu-toggle mobile-toggle" | ||
> | ||
<IconTOC aria-hidden="true" /> | ||
On this page | ||
</Button> | ||
) : null} | ||
|
||
<View | ||
className={classNames( | ||
|
@@ -149,6 +179,46 @@ export const LayoutHeader = ({ | |
</div> | ||
</View> | ||
</View> | ||
|
||
{showTOC ? ( | ||
<View | ||
className={classNames('layout-sidebar', 'right-menu', { | ||
'layout-sidebar--expanded': tocOpen | ||
})} | ||
> | ||
<View | ||
className={classNames('layout-sidebar__backdrop', { | ||
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. |
||
'layout-sidebar__backdrop--expanded': tocOpen | ||
})} | ||
onClick={() => toggleTocOpen(false)} | ||
></View> | ||
<View | ||
className={classNames('layout-sidebar__inner', 'right-menu', { | ||
'layout-sidebar__inner--expanded-right': tocOpen | ||
})} | ||
> | ||
<Button | ||
size="small" | ||
colorTheme="overlay" | ||
className={classNames( | ||
'layout-sidebar__mobile-toggle', | ||
'right-menu', | ||
{ | ||
'layout-sidebar__mobile-toggle--open': tocOpen | ||
} | ||
)} | ||
ref={sidebarTocButtonRef} | ||
onClick={() => handleTocToggle()} | ||
> | ||
<IconDoubleChevron /> | ||
<VisuallyHidden>Close table of contents</VisuallyHidden> | ||
</Button> | ||
<div className="layout-sidebar-menu"> | ||
<TableOfContents headers={tocHeadings} forDesktop={false} /> | ||
</div> | ||
</View> | ||
</View> | ||
) : null} | ||
</View> | ||
); | ||
}; |
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
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.