Skip to content
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

fix: improve sidebar accessibility structure (#8429) #11038

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ function DocSidebarDesktop({path, sidebar, onCollapse, isHidden}: Props) {
} = useThemeConfig();

return (
<div
<nav
className={clsx(
styles.sidebar,
hideOnScroll && styles.sidebarWithHideableNavbar,
isHidden && styles.sidebarHidden,
)}>
{hideOnScroll && <Logo tabIndex={-1} className={styles.sidebarLogo} />}
)}
aria-label="docs sidebar">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All our Aria labels should use our translation framework so that they can be localized

{hideOnScroll && (
<Logo tabIndex={-1} className={styles.sidebarLogo} aria-hidden="true" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding, the aria-hidden="true" shouldn't always be applied.

When the site navbar is shown, then that logo is behind the navbar so it's hidden:

CleanShot 2025-03-28 at 10 16 14

However when the site gets scrolled and the navbar disappears, this logo becomes visible, and is an actual link to the site homepage. In this case I don't believe applying aria-hidden is a good idea

CleanShot 2025-03-28 at 10 16 50

)}
<Content path={path} sidebar={sidebar} />
{hideable && <CollapseButton onClick={onCollapse} />}
</div>
</nav>
);
}

Expand Down
1 change: 0 additions & 1 deletion packages/docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"combine-promises": "^1.1.0",
"commander": "^5.1.0",
"core-js": "^3.31.1",
"del": "^6.1.1",
"detect-port": "^1.5.1",
"escape-html": "^1.0.3",
"eta": "^2.2.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/docusaurus/src/commands/build/buildLocale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {
} from '@docusaurus/types';
import type {SiteCollectedData} from '../../common';
import {BuildCLIOptions} from './build';
import clearPath from '../utils/clearPath';

export type BuildLocaleParams = {
siteDir: string;
Expand Down Expand Up @@ -77,6 +78,11 @@ export async function buildLocale({
props,
configureWebpackUtils,
}),

// We also clear website/build dir
// returns void, no useful result needed before compilation
// See also https://github.com/facebook/docusaurus/pull/11037
clearPath(outDir),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not related to accessibility, please remove all the unwanted changes from this PR diff

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for your feedback and sorry for the late response !

I will just clarify this points :

About the <aside> replacement:
You're totally right — I didn’t actually replace an <aside> in the current markup. What I meant was that I replaced a generic container (previously a <div> or <aside> depending on the context) with a more semantic <nav aria-label="docs sidebar">. Sorry for the confusion there

Regarding aria-hidden="true" on the logo:
Good catch. I see your point now, applying aria-hidden unconditionally isn't ideal. The logo is indeed visible and interactive when the navbar scrolls away, so hiding it at that point isn’t great for accessibility.

Screen reader testing:
I tested with NVDA on Windows. Before the change, the logo was inconsistently handled, and the outer <aside> (when present) sometimes caused duplicate landmarks to be announced.

Translation of aria-label:
Thanks for pointing that out

Unrelated changes:
You're absolutely right — the change to buildLocale.ts doesn't belong in this PR.

Appreciate the thoughtful review!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great

Let me know if you plan to improve the PR to meet the requirements

]),
);

Expand Down
3 changes: 2 additions & 1 deletion packages/docusaurus/src/commands/clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import {
DEFAULT_BUILD_DIR_NAME,
GENERATED_FILES_DIR_NAME,
} from '@docusaurus/utils';
import clearPath from './utils/clearPath';

async function removePath(entry: {path: string; description: string}) {
if (!(await fs.pathExists(entry.path))) {
return;
}
try {
await fs.remove(entry.path);
await clearPath(entry.path);
logger.success`Removed the ${entry.description} at path=${path.relative(
process.cwd(),
entry.path,
Expand Down
22 changes: 22 additions & 0 deletions packages/docusaurus/src/commands/utils/clearPath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import path from 'path';
import {rm} from 'fs/promises';
import {PerfLogger} from '@docusaurus/logger';

/**
* @param pathToClear
*/
export default async function clearPath(pathToClear: string): Promise<void> {
return PerfLogger.async(
`clearPath ${path.relative(process.cwd(), pathToClear)}`,
async () => {
await rm(pathToClear, {recursive: true, force: true});
},
);
}
3 changes: 0 additions & 3 deletions packages/docusaurus/src/webpack/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import HtmlWebpackPlugin from 'html-webpack-plugin';
import {getProgressBarPlugin} from '@docusaurus/bundler';
import {createBaseConfig} from './base';
import ChunkAssetPlugin from './plugins/ChunkAssetPlugin';
import CleanWebpackPlugin from './plugins/CleanWebpackPlugin';
import ForceTerminatePlugin from './plugins/ForceTerminatePlugin';
import {createStaticDirectoriesCopyPlugin} from './plugins/StaticDirectoriesCopyPlugin';
import type {
Expand Down Expand Up @@ -164,8 +163,6 @@ export async function createBuildClientConfig({
{
plugins: [
new ForceTerminatePlugin(),
// Remove/clean build folders before building bundles.
new CleanWebpackPlugin({verbose: false}),
// Visualize size of webpack output files with an interactive zoomable
// tree map.
bundleAnalyzer && new BundleAnalyzerPlugin(),
Expand Down
263 changes: 0 additions & 263 deletions packages/docusaurus/src/webpack/plugins/CleanWebpackPlugin.ts

This file was deleted.

1 change: 0 additions & 1 deletion project-words.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Project Words - DO NOT TOUCH - This is updated through CI
abernathyca
Adriaan
Agan
alexbdebrie
Alexey
algoliasearch
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7339,7 +7339,7 @@ define-properties@^1.1.3, define-properties@^1.1.4, define-properties@^1.2.0, de
has-property-descriptors "^1.0.0"
object-keys "^1.1.1"

del@^6.0.0, del@^6.1.1:
del@^6.0.0:
version "6.1.1"
resolved "https://registry.yarnpkg.com/del/-/del-6.1.1.tgz#3b70314f1ec0aa325c6b14eb36b95786671edb7a"
integrity sha512-ua8BhapfP0JUJKC/zV9yHHDW/rDoDxP4Zhn3AkA6/xT6gY7jYXJiaeyBZznYVujhZZET+UgcbZiQ7sN3WqcImg==
Expand Down