From 4fb26f6d6e09ee8c973efed43e1abe79a91ac16c Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Fri, 13 Dec 2024 07:10:45 -0600 Subject: [PATCH] refactor: Make roles signalish --- src/jsx.d.ts | 120 +++++++++++++++++++++----------- test/ts/dom-attributes-test.tsx | 7 ++ 2 files changed, 85 insertions(+), 42 deletions(-) diff --git a/src/jsx.d.ts b/src/jsx.d.ts index 4744f77499..c83ce634e4 100644 --- a/src/jsx.d.ts +++ b/src/jsx.d.ts @@ -1568,7 +1568,7 @@ export namespace JSXInternal { interface ArticleHTMLAttributes extends HTMLAttributes { - role?: + role?: Signalish< | 'article' | 'application' | 'document' @@ -1576,12 +1576,14 @@ export namespace JSXInternal { | 'main' | 'none' | 'presentation' - | 'region'; + | 'region' + | undefined + >; } interface AsideHTMLAttributes extends HTMLAttributes { - role?: + role?: Signalish< | 'complementary' | 'feed' | 'none' @@ -1594,12 +1596,14 @@ export namespace JSXInternal { | 'doc-footnote' | 'doc-glossary' | 'doc-pullquote' - | 'doc-tip'; + | 'doc-tip' + | undefined + >; } interface AudioHTMLAttributes extends MediaHTMLAttributes { - role?: 'application'; + role?: Signalish<'application' | undefined>; } interface BaseHTMLAttributes @@ -1621,7 +1625,7 @@ export namespace JSXInternal { interface BrHTMLAttributes extends HTMLAttributes { - role?: 'none' | 'presentation'; + role?: Signalish<'none' | 'presentation' | undefined>; } interface ButtonHTMLAttributes @@ -1643,7 +1647,7 @@ export namespace JSXInternal { popoverTarget?: Signalish; popovertargetaction?: Signalish<'hide' | 'show' | 'toggle' | undefined>; popoverTargetAction?: Signalish<'hide' | 'show' | 'toggle' | undefined>; - role?: + role?: Signalish< | 'button' | 'checkbox' | 'combobox' @@ -1658,7 +1662,9 @@ export namespace JSXInternal { | 'slider' | 'switch' | 'tab' - | 'treeitem'; + | 'treeitem' + | undefined + >; type?: Signalish<'submit' | 'reset' | 'button' | undefined>; value?: Signalish; } @@ -1694,7 +1700,7 @@ export namespace JSXInternal { interface DataListHTMLAttributes extends HTMLAttributes { - role?: 'listbox'; + role?: Signalish<'listbox' | undefined>; } interface DdHTMLAttributes @@ -1713,7 +1719,7 @@ export namespace JSXInternal { extends HTMLAttributes { open?: Signalish; onToggle?: GenericEventHandler | undefined; - role?: 'group'; + role?: Signalish<'group' | undefined>; } interface DialogHTMLAttributes @@ -1721,23 +1727,25 @@ export namespace JSXInternal { onCancel?: GenericEventHandler | undefined; onClose?: GenericEventHandler | undefined; open?: Signalish; - role?: 'dialog' | 'alertdialog'; + role?: Signalish<'dialog' | 'alertdialog' | undefined>; } interface DlHTMLAttributes extends HTMLAttributes { - role?: 'group' | 'list' | 'none' | 'presentation'; + role?: Signalish<'group' | 'list' | 'none' | 'presentation' | undefined>; } interface DtHTMLAttributes extends HTMLAttributes { - role?: 'listitem'; + role?: Signalish<'listitem' | undefined>; } interface EmbedHTMLAttributes extends HTMLAttributes { height?: Signalish; - role?: 'application' | 'document' | 'img' | 'none' | 'presentation'; + role?: Signalish< + 'application' | 'document' | 'img' | 'none' | 'presentation' | undefined + >; src?: Signalish; type?: Signalish; width?: Signalish; @@ -1748,23 +1756,27 @@ export namespace JSXInternal { disabled?: Signalish; form?: Signalish; name?: Signalish; - role?: 'group' | 'none' | 'presentation' | 'radiogroup'; + role?: Signalish< + 'group' | 'none' | 'presentation' | 'radiogroup' | undefined + >; } interface FigcaptionHTMLAttributes extends HTMLAttributes { - role?: 'group' | 'none' | 'presentation'; + role?: Signalish<'group' | 'none' | 'presentation' | undefined>; } interface FooterHTMLAttributes extends HTMLAttributes { - role?: + role?: Signalish< | 'contentinfo' | 'generic' | 'group' | 'none' | 'presentation' - | 'doc-footnote'; + | 'doc-footnote' + | undefined + >; } interface FormHTMLAttributes @@ -1781,13 +1793,15 @@ export namespace JSXInternal { novalidate?: Signalish; noValidate?: Signalish; rel?: Signalish; - role?: 'form' | 'none' | 'presentation' | 'search'; + role?: Signalish<'form' | 'none' | 'presentation' | 'search' | undefined>; target?: Signalish; } interface HeadingHTMLAttributes extends HTMLAttributes { - role?: 'heading' | 'none' | 'presentation' | 'tab' | 'doc-subtitle'; + role?: Signalish< + 'heading' | 'none' | 'presentation' | 'tab' | 'doc-subtitle' | undefined + >; } interface HeadHTMLAttributes @@ -1797,17 +1811,21 @@ export namespace JSXInternal { interface HeaderHTMLAttributes extends HTMLAttributes { - role?: 'banner' | 'generic' | 'group' | 'none' | 'presentation'; + role?: Signalish< + 'banner' | 'generic' | 'group' | 'none' | 'presentation' | undefined + >; } interface HrHTMLAttributes extends HTMLAttributes { - role?: 'separator' | 'none' | 'presentation' | 'doc-pagebreak'; + role?: Signalish< + 'separator' | 'none' | 'presentation' | 'doc-pagebreak' | undefined + >; } interface HtmlHTMLAttributes extends HTMLAttributes { - role?: 'document'; + role?: Signalish<'document' | undefined>; } interface IframeHTMLAttributes @@ -1828,7 +1846,9 @@ export namespace JSXInternal { name?: Signalish; referrerpolicy?: Signalish; referrerPolicy?: Signalish; - role?: 'application' | 'document' | 'img' | 'none' | 'presentation'; + role?: Signalish< + 'application' | 'document' | 'img' | 'none' | 'presentation' | undefined + >; sandbox?: Signalish; /** @deprecated */ scrolling?: Signalish; @@ -2001,7 +2021,7 @@ export namespace JSXInternal { interface MainHTMLAttributes extends HTMLAttributes { - role?: 'main'; + role?: Signalish<'main' | undefined>; } interface MapHTMLAttributes @@ -2080,19 +2100,21 @@ export namespace JSXInternal { max?: Signalish; min?: Signalish; optimum?: Signalish; - role?: 'meter'; + role?: Signalish<'meter' | undefined>; value?: Signalish; } interface NavHTMLAttributes extends HTMLAttributes { - role?: + role?: Signalish< | 'navigation' | 'menu' | 'menubar' | 'none' | 'presentation' - | 'tablist'; + | 'tablist' + | undefined + >; } interface NoScriptHTMLAttributes @@ -2107,7 +2129,7 @@ export namespace JSXInternal { form?: Signalish; height?: Signalish; name?: Signalish; - role?: 'application' | 'document' | 'img'; + role?: Signalish<'application' | 'document' | 'img' | undefined>; type?: Signalish; usemap?: Signalish; useMap?: Signalish; @@ -2118,7 +2140,7 @@ export namespace JSXInternal { interface OlHTMLAttributes extends HTMLAttributes { reversed?: Signalish; - role?: + role?: Signalish< | 'list' | 'group' | 'listbox' @@ -2129,7 +2151,9 @@ export namespace JSXInternal { | 'radiogroup' | 'tablist' | 'toolbar' - | 'tree'; + | 'tree' + | undefined + >; start?: Signalish; type?: Signalish<'1' | 'a' | 'A' | 'i' | 'I' | undefined>; } @@ -2138,14 +2162,14 @@ export namespace JSXInternal { extends HTMLAttributes { disabled?: Signalish; label?: Signalish; - role?: 'group'; + role?: Signalish<'group' | undefined>; } interface OptionHTMLAttributes extends HTMLAttributes { disabled?: Signalish; label?: Signalish; - role?: 'option'; + role?: Signalish<'option' | undefined>; selected?: Signalish; value?: Signalish; } @@ -2173,7 +2197,7 @@ export namespace JSXInternal { interface ProgressHTMLAttributes extends HTMLAttributes { max?: Signalish; - role?: 'progressbar'; + role?: Signalish<'progressbar' | undefined>; value?: Signalish; } @@ -2204,7 +2228,15 @@ export namespace JSXInternal { interface SearchHTMLAttributes extends HTMLAttributes { - role?: 'search' | 'form' | 'group' | 'none' | 'presentation' | 'region'; + role?: Signalish< + | 'search' + | 'form' + | 'group' + | 'none' + | 'presentation' + | 'region' + | undefined + >; } interface SelectHTMLAttributes @@ -2218,7 +2250,7 @@ export namespace JSXInternal { name?: Signalish; required?: Signalish; // TODO: Select w/ multiple - role?: + role?: Signalish< | 'region' | 'generic' | 'alert' @@ -2268,7 +2300,9 @@ export namespace JSXInternal { | 'doc-prologue' | 'doc-pullquote' | 'doc-qna' - | 'doc-toc'; + | 'doc-toc' + | undefined + >; size?: Signalish; value?: Signalish; onChange?: GenericEventHandler | undefined; @@ -2348,7 +2382,7 @@ export namespace JSXInternal { placeholder?: Signalish; readOnly?: Signalish; required?: Signalish; - role?: 'textbox'; + role?: Signalish<'textbox' | undefined>; rows?: Signalish; value?: Signalish; wrap?: Signalish; @@ -2392,7 +2426,7 @@ export namespace JSXInternal { interface UlHTMLAttributes extends HTMLAttributes { - role?: + role?: Signalish< | 'list' | 'group' | 'listbox' @@ -2403,7 +2437,9 @@ export namespace JSXInternal { | 'radiogroup' | 'tablist' | 'toolbar' - | 'tree'; + | 'tree' + | undefined + >; } interface VideoHTMLAttributes @@ -2413,12 +2449,12 @@ export namespace JSXInternal { width?: Signalish; disablePictureInPicture?: Signalish; disableRemotePlayback?: Signalish; - role?: 'application'; + role?: Signalish<'application' | undefined>; } interface WbrHTMLAttributes extends HTMLAttributes { - role?: 'none' | 'presentation'; + role?: Signalish<'none' | 'presentation' | undefined>; } export type DetailedHTMLProps< diff --git a/test/ts/dom-attributes-test.tsx b/test/ts/dom-attributes-test.tsx index bde40726be..29b0aaec98 100644 --- a/test/ts/dom-attributes-test.tsx +++ b/test/ts/dom-attributes-test.tsx @@ -15,6 +15,13 @@ function createSignal(value: T): JSX.SignalLike { // @ts-expect-error A button should not have a role of presentation const badAriaRole =