mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-22 13:37:05 +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,
|
useTitleFormatter,
|
||||||
useAlternatePageUtils,
|
useAlternatePageUtils,
|
||||||
useThemeConfig,
|
useThemeConfig,
|
||||||
|
keyboardFocusedClassName,
|
||||||
} from '@docusaurus/theme-common';
|
} from '@docusaurus/theme-common';
|
||||||
import {useLocation} from '@docusaurus/router';
|
import {useLocation} from '@docusaurus/router';
|
||||||
|
|
||||||
|
@ -101,6 +102,9 @@ export default function LayoutHead(props: Props): JSX.Element {
|
||||||
<title>{pageTitle}</title>
|
<title>{pageTitle}</title>
|
||||||
<meta property="og:title" content={pageTitle} />
|
<meta property="og:title" content={pageTitle} />
|
||||||
<meta name="twitter:card" content="summary_large_image" />
|
<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>
|
</Head>
|
||||||
|
|
||||||
{/* image can override the default image */}
|
{/* image can override the default image */}
|
||||||
|
|
|
@ -9,12 +9,12 @@ import {useEffect} from 'react';
|
||||||
|
|
||||||
import './styles.css';
|
import './styles.css';
|
||||||
|
|
||||||
|
export const keyboardFocusedClassName = 'navigation-with-keyboard';
|
||||||
|
|
||||||
// This hook detect keyboard focus indicator to not show outline for mouse users
|
// 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
|
// Inspired by https://hackernoon.com/removing-that-ugly-focus-ring-and-keeping-it-too-6c8727fefcd2
|
||||||
export default function useKeyboardNavigation(): void {
|
export default function useKeyboardNavigation(): void {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const keyboardFocusedClassName = 'navigation-with-keyboard';
|
|
||||||
|
|
||||||
function handleOutlineStyles(e: MouseEvent | KeyboardEvent) {
|
function handleOutlineStyles(e: MouseEvent | KeyboardEvent) {
|
||||||
if (e.type === 'keydown' && (e as KeyboardEvent).key === 'Tab') {
|
if (e.type === 'keydown' && (e as KeyboardEvent).key === 'Tab') {
|
||||||
document.body.classList.add(keyboardFocusedClassName);
|
document.body.classList.add(keyboardFocusedClassName);
|
||||||
|
|
|
@ -126,7 +126,10 @@ export {
|
||||||
} from './utils/tabGroupChoiceUtils';
|
} from './utils/tabGroupChoiceUtils';
|
||||||
|
|
||||||
export {default as useHideableNavbar} from './hooks/useHideableNavbar';
|
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 usePrismTheme} from './hooks/usePrismTheme';
|
||||||
export {default as useLockBodyScroll} from './hooks/useLockBodyScroll';
|
export {default as useLockBodyScroll} from './hooks/useLockBodyScroll';
|
||||||
export {default as useWindowSize} from './hooks/useWindowSize';
|
export {default as useWindowSize} from './hooks/useWindowSize';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue