From 61ee2adc0f5fa96f47e229e707c25a1c95757681 Mon Sep 17 00:00:00 2001 From: Hitesh Shetty <48558898+hiteshshetty-dev@users.noreply.github.com> Date: Thu, 28 Aug 2025 02:14:52 +0530 Subject: [PATCH] fix: keyboard accessibility for example site (#5946) * fix: keyboard accessibility for example site * chore: remove redundant assignment of DOM attribute Co-authored-by: Joe Anderson * refactor: replace MouseEvent with PointerEvent for improved button interactions --------- Co-authored-by: Joe Anderson --- site/examples/ts/code-highlighting.tsx | 6 ++-- site/examples/ts/components/index.tsx | 11 ++++--- site/examples/ts/editable-voids.tsx | 6 ++-- site/examples/ts/iframe.tsx | 6 ++-- site/examples/ts/images.tsx | 9 ++++-- site/examples/ts/inlines.tsx | 15 +++++++--- site/examples/ts/richtext.tsx | 14 ++++----- site/pages/examples/[example].tsx | 41 ++++++++++++++++++++++++-- 8 files changed, 79 insertions(+), 29 deletions(-) diff --git a/site/examples/ts/code-highlighting.tsx b/site/examples/ts/code-highlighting.tsx index 2bab94b5d..6965103fc 100644 --- a/site/examples/ts/code-highlighting.tsx +++ b/site/examples/ts/code-highlighting.tsx @@ -10,7 +10,7 @@ import 'prismjs/components/prism-python' import 'prismjs/components/prism-sql' import 'prismjs/components/prism-tsx' import 'prismjs/components/prism-typescript' -import React, { ChangeEvent, MouseEvent, useCallback, useState } from 'react' +import React, { ChangeEvent, PointerEvent, useCallback, useState } from 'react' import { Editor, Element, @@ -143,10 +143,10 @@ const CodeBlockButton = () => { diff --git a/site/examples/ts/components/index.tsx b/site/examples/ts/components/index.tsx index 2cf5b8df9..df0b5ebae 100644 --- a/site/examples/ts/components/index.tsx +++ b/site/examples/ts/components/index.tsx @@ -20,14 +20,16 @@ export const Button = React.forwardRef( reversed: boolean } & BaseProps >, - ref: Ref + ref: Ref ) => ( - ) diff --git a/site/examples/ts/editable-voids.tsx b/site/examples/ts/editable-voids.tsx index 55dd3da7f..06d050bb5 100644 --- a/site/examples/ts/editable-voids.tsx +++ b/site/examples/ts/editable-voids.tsx @@ -1,5 +1,5 @@ import { css } from '@emotion/css' -import React, { MouseEvent, useMemo, useState } from 'react' +import React, { PointerEvent, useMemo, useState } from 'react' import { createEditor, Descendant, Transforms } from 'slate' import { withHistory } from 'slate-history' import { @@ -130,10 +130,10 @@ const InsertEditableVoidButton = () => { const editor = useSlateStatic() return ( diff --git a/site/examples/ts/iframe.tsx b/site/examples/ts/iframe.tsx index cb79b3bf9..5de19186c 100644 --- a/site/examples/ts/iframe.tsx +++ b/site/examples/ts/iframe.tsx @@ -1,5 +1,5 @@ import isHotkey from 'is-hotkey' -import React, { MouseEvent, useCallback, useMemo, useState } from 'react' +import React, { PointerEvent, useCallback, useMemo, useState } from 'react' import { createPortal } from 'react-dom' import { Editor, createEditor, Descendant } from 'slate' import { withHistory } from 'slate-history' @@ -115,10 +115,10 @@ const MarkButton = ({ format, icon }: MarkButtonProps) => { return ( diff --git a/site/examples/ts/images.tsx b/site/examples/ts/images.tsx index 41d84f555..a6a0aee59 100644 --- a/site/examples/ts/images.tsx +++ b/site/examples/ts/images.tsx @@ -2,7 +2,7 @@ import { css } from '@emotion/css' import imageExtensions from 'image-extensions' import isHotkey from 'is-hotkey' import isUrl from 'is-url' -import React, { MouseEvent, useMemo } from 'react' +import React, { PointerEvent, useMemo } from 'react' import { Descendant, Transforms, createEditor } from 'slate' import { withHistory } from 'slate-history' import { @@ -135,6 +135,9 @@ const Image = ({ /> @@ -267,10 +267,10 @@ const MarkButton = ({ format, icon }: MarkButtonProps) => { return ( diff --git a/site/pages/examples/[example].tsx b/site/pages/examples/[example].tsx index df81ee9ab..c14fc7a1e 100644 --- a/site/pages/examples/[example].tsx +++ b/site/pages/examples/[example].tsx @@ -135,6 +135,9 @@ const TabList = ({ ...props }: React.HTMLAttributes & { isVisible?: boolean }) => (
) @@ -171,10 +177,16 @@ const TabListUnderlay = ({ ) const TabButton = (props: React.HTMLAttributes) => ( - { e.stopPropagation() setShowTabs(!showTabs) }} + onKeyDown={(e: React.KeyboardEvent) => { + if (e.key === 'Escape') { + setShowTabs(false) + } + }} + aria-expanded={showTabs} > menu @@ -368,7 +388,17 @@ const ExamplePage = ({ example }: { example: string }) => { legacyBehavior passHref > - setShowTabs(false)}>{n} + setShowTabs(false)} + active={p === path} + onKeyDown={(e: React.KeyboardEvent) => { + if (e.key === 'Escape') { + setShowTabs(false) + } + }} + > + {n} + ))} @@ -393,6 +423,11 @@ const ExamplePage = ({ example }: { example: string }) => { setShowTabs(false)} + onKeyDown={(e: React.KeyboardEvent) => { + if (e.key === 'Escape') { + setShowTabs(false) + } + }} />