mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-22 05:27:00 +02:00
fix(theme-classic): make focused link outlined with JS disabled (#6505)
This commit is contained in:
parent
caa9d281c3
commit
01c6f15b15
3 changed files with 10 additions and 3 deletions
|
@ -17,6 +17,7 @@ import {
|
|||
useTitleFormatter,
|
||||
useAlternatePageUtils,
|
||||
useThemeConfig,
|
||||
keyboardFocusedClassName,
|
||||
} from '@docusaurus/theme-common';
|
||||
import {useLocation} from '@docusaurus/router';
|
||||
|
||||
|
@ -101,6 +102,9 @@ export default function LayoutHead(props: Props): JSX.Element {
|
|||
<title>{pageTitle}</title>
|
||||
<meta property="og:title" content={pageTitle} />
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
{/* The keyboard focus class name need to be applied when SSR so links
|
||||
are outlined when JS is disabled */}
|
||||
<body className={keyboardFocusedClassName} />
|
||||
</Head>
|
||||
|
||||
{/* image can override the default image */}
|
||||
|
|
|
@ -9,12 +9,12 @@ import {useEffect} from 'react';
|
|||
|
||||
import './styles.css';
|
||||
|
||||
export const keyboardFocusedClassName = 'navigation-with-keyboard';
|
||||
|
||||
// This hook detect keyboard focus indicator to not show outline for mouse users
|
||||
// Inspired by https://hackernoon.com/removing-that-ugly-focus-ring-and-keeping-it-too-6c8727fefcd2
|
||||
export default function useKeyboardNavigation(): void {
|
||||
useEffect(() => {
|
||||
const keyboardFocusedClassName = 'navigation-with-keyboard';
|
||||
|
||||
function handleOutlineStyles(e: MouseEvent | KeyboardEvent) {
|
||||
if (e.type === 'keydown' && (e as KeyboardEvent).key === 'Tab') {
|
||||
document.body.classList.add(keyboardFocusedClassName);
|
||||
|
|
|
@ -126,7 +126,10 @@ export {
|
|||
} from './utils/tabGroupChoiceUtils';
|
||||
|
||||
export {default as useHideableNavbar} from './hooks/useHideableNavbar';
|
||||
export {default as useKeyboardNavigation} from './hooks/useKeyboardNavigation';
|
||||
export {
|
||||
default as useKeyboardNavigation,
|
||||
keyboardFocusedClassName,
|
||||
} from './hooks/useKeyboardNavigation';
|
||||
export {default as usePrismTheme} from './hooks/usePrismTheme';
|
||||
export {default as useLockBodyScroll} from './hooks/useLockBodyScroll';
|
||||
export {default as useWindowSize} from './hooks/useWindowSize';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue