Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

refactor(settings): improve accessibility and styling for settings navigation (#8701)

brios03620a4a1bdb
diff --git a/frontend/src/editor/core/components/settings/useActiveHeading.ts b/frontend/src/editor/core/components/settings/useActiveHeading.ts
index 7ef525883f..fbd016bce1 100644
--- a/frontend/src/editor/core/components/settings/useActiveHeading.ts
+++ b/frontend/src/editor/core/components/settings/useActiveHeading.ts
@@ -15,6 +15,11 @@ function writeHash(id: string): void {
);
}
+export interface HeadingFocusOptions {
+ /** Move keyboard focus to the target as well as scrolling to it. */
+ moveFocus?: boolean;
+}
+
/**
* Which card the reader is on, mirrored into the URL as `#slug`.
*
@@ -24,14 +29,17 @@ function writeHash(id: string): void {
export function useActiveHeading(
container: HTMLElement | null,
headings: SectionHeading[],
-): { active: string | null; focus: (id: string) => void } {
+): {
+ active: string | null;
+ focus: (id: string, options?: HeadingFocusOptions) => void;
+} {
const [active, setActive] = useState<string | null>(null);
// A click scrolls smoothly; without this the spy reads the frames on the way
// and overwrites the slug the reader just asked for.
const settleUntil = useRef(0);
const focus = useCallback(
- (id: string) => {
+ (id: string, { moveFocus = false }: HeadingFocusOptions = {}) => {
const el = document.getElementById(id);
if (!el) return;
// Unfold first, or there is nothing to scroll to: the anchor is either a
@@ -51,16 +59,31 @@ export function useActiveHeading(
// Scroll the settings scroller itself, not scrollIntoView: that walks the
// whole ancestor chain and drags the app frame up under the title bar.
if (container) {
+ // The phone layout sticks the back bar over the scroller; landing the
+ // heading at the top edge would put the bar over it.
+ const stickyOffset =
+ container.querySelector<HTMLElement>(".settings-page__mobile-bar")
+ ?.offsetHeight ?? 0;
container.scrollTo({
top:
el.getBoundingClientRect().top -
container.getBoundingClientRect().top +
- container.scrollTop,
+ container.scrollTop -
+ stickyOffset,
behavior: "smooth",
});
} else {
el.scrollIntoView({ behavior: "smooth", block: "start" });
}
+ if (moveFocus) {
+ // Pages that still draw a plain heading are not focusable by default.
+ if (
+ !el.matches("a[href], button, input, select, textarea, [tabindex]")
+ ) {
+ el.setAttribute("tabindex", "-1");
+ }
+ el.focus({ preventScroll: true });
+ }
el.classList.add("settings-focus-target");
window.setTimeout(
() => el.classList.remove("settings-focus-target"),
@@ -80,6 +103,9 @@ export function useActiveHeading(
const read = () => {
frame = 0;
if (Date.now() < settleUntil.current) return;
+ // The phone layout hides this pane instead of unmounting it; every rect
+ // then reads zero, which would elect the last heading as current.
+ if (container.clientHeight === 0) return;
const line = container.getBoundingClientRect().top + ACTIVE_LINE;
let current = headings[0]?.id ?? null;
for (const h of headings) {
diff --git a/frontend/src/editor/core/components/shared/config/settingsSections.css b/frontend/src/editor/core/components/shared/config/settingsSections.css
index 364858ef2c..5ac85c56ac 100644
--- a/frontend/src/editor/core/components/shared/config/settingsSections.css
+++ b/frontend/src/editor/core/components/shared/config/settingsSections.css
@@ -1,26 +1,20 @@
/* Styles shared by every settings section, and the section chrome the settings
page draws around them. */
-/* Deep-link highlight: pulses the control the super search jumped to
+/* Deep-link highlight: fades the control the super search jumped to
(navigated via /settings/{section}?focus={anchor}). */
@keyframes settings-focus-pulse {
0% {
- box-shadow: 0 0 0 3px var(--mantine-color-blue-5);
- background: color-mix(
- in srgb,
- var(--mantine-color-blue-5) 16%,
- transparent
- );
+ background-color: var(--c-primary-subtle);
}
100% {
- box-shadow: 0 0 0 6px transparent;
- background: transparent;
+ background-color: transparent;
}
}
.settings-focus-target {
animation: settings-focus-pulse 1.8s ease-out;
- border-radius: 8px;
+ border-radius: var(--radius-md);
scroll-margin: 1rem;
}
diff --git a/frontend/src/editor/core/pages/SettingsPage.css b/frontend/src/editor/core/pages/SettingsPage.css
index fc6cc77693..4069b3dae3 100644
--- a/frontend/src/editor/core/pages/SettingsPage.css
+++ b/frontend/src/editor/core/pages/SettingsPage.css
@@ -105,11 +105,7 @@
.settings-page .modal-nav-item.active {
background: var(--c-primary-subtle);
- color: var(--c-accent-fg, var(--c-primary));
-}
-
-.settings-page .modal-nav-item.active .settings-page__nav-label {
- font-weight: 600;
+ color: var(--c-accent-text);
}
.settings-page .modal-nav-item[aria-disabled="true"] {
@@ -279,13 +275,12 @@
.settings-page__subnav {
list-style: none;
margin: 0.125rem 0 0.375rem;
- padding: 0 0 0 1.75rem;
+ /* Aligns the heading text with the rail rows' labels, which sit past the icon. */
+ padding: 0;
+ padding-inline-start: 1.875rem;
display: flex;
flex-direction: column;
gap: 0.0625rem;
- /* One rule down the group, so the children read as belonging to the row. */
- border-inline-start: 1px solid var(--c-border-subtle);
- margin-inline-start: 1rem;
}
.settings-page__subnav-item {
@@ -309,9 +304,8 @@
/* Follows the scroll, so the rail always says where you are. */
.settings-page__subnav-item[aria-current="true"] {
- color: var(--c-text);
- font-weight: 600;
- box-shadow: inset 2px 0 0 var(--c-accent-fg, var(--c-primary));
+ color: var(--c-accent-text);
+ font-weight: 500;
}
.settings-page__subnav-item:focus-visible {
diff --git a/frontend/src/editor/core/pages/SettingsPage.tsx b/frontend/src/editor/core/pages/SettingsPage.tsx
index b7d71a2d98..960148fb8a 100644
--- a/frontend/src/editor/core/pages/SettingsPage.tsx
+++ b/frontend/src/editor/core/pages/SettingsPage.tsx
@@ -167,6 +167,20 @@ const SettingsPageInner: React.FC = () => {
headings,
);
+ // On phones the headings are listed on the nav pane, so a heading tap has to
+ // reveal the content before the scroll can measure it.
+ const jumpToHeading = useCallback(
+ (id: string) => {
+ if (!isMobile) {
+ focusHeading(id, { moveFocus: true });
+ return;
+ }
+ setMobilePane("content");
+ window.requestAnimationFrame(() => focusHeading(id, { moveFocus: true }));
+ },
+ [focusHeading, isMobile],
+ );
+
const anchor = decodeURIComponent(location.hash.replace(/^#/, ""));
const activeKey = activeItem?.key;
@@ -314,7 +328,7 @@ const SettingsPageInner: React.FC = () => {
}
onClick={(event) => {
event.preventDefault();
- focusHeading(h.id);
+ jumpToHeading(h.id);
}}
>
{h.label}