Skip to content

Commit 3bb1113

Browse files
committed
refactor: Make roles signalish
1 parent 9f2cb57 commit 3bb1113

2 files changed

Lines changed: 41 additions & 34 deletions

File tree

src/jsx.d.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,17 +1568,17 @@ export namespace JSXInternal {
15681568

15691569
interface ArticleHTMLAttributes<T extends EventTarget>
15701570
extends HTMLAttributes<T> {
1571-
role?: 'article' | 'application' | 'document' | 'feed' | 'main' | 'none' | 'presentation' | 'region';
1571+
role?: Signalish<'article' | 'application' | 'document' | 'feed' | 'main' | 'none' | 'presentation' | 'region' | undefined>;
15721572
}
15731573

15741574
interface AsideHTMLAttributes<T extends EventTarget>
15751575
extends HTMLAttributes<T> {
1576-
role?: 'complementary' | 'feed' | 'none' | 'note' | 'presentation' | 'region' | 'search' | 'doc-dedication' | 'doc-example' | 'doc-footnote' | 'doc-glossary' | 'doc-pullquote' | 'doc-tip';
1576+
role?: Signalish<'complementary' | 'feed' | 'none' | 'note' | 'presentation' | 'region' | 'search' | 'doc-dedication' | 'doc-example' | 'doc-footnote' | 'doc-glossary' | 'doc-pullquote' | 'doc-tip' | undefined>;
15771577
}
15781578

15791579
interface AudioHTMLAttributes<T extends EventTarget>
15801580
extends MediaHTMLAttributes<T> {
1581-
role?: 'application';
1581+
role?: Signalish<'application' | undefined>;
15821582
}
15831583

15841584
interface BaseHTMLAttributes<T extends EventTarget>
@@ -1598,7 +1598,7 @@ export namespace JSXInternal {
15981598
}
15991599

16001600
interface BrHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
1601-
role?: 'none' | 'presentation';
1601+
role?: Signalish<'none' | 'presentation' | undefined>;
16021602
}
16031603

16041604
interface ButtonHTMLAttributes<T extends EventTarget>
@@ -1620,7 +1620,7 @@ export namespace JSXInternal {
16201620
popoverTarget?: Signalish<string | undefined>;
16211621
popovertargetaction?: Signalish<'hide' | 'show' | 'toggle' | undefined>;
16221622
popoverTargetAction?: Signalish<'hide' | 'show' | 'toggle' | undefined>;
1623-
role?: 'button' | 'checkbox' | 'combobox' | 'gridcell' | 'link' | 'menuitem' | 'menuitemcheckbox' | 'menuitemradio' | 'option' | 'radio' | 'separator' | 'slider' | 'switch' | 'tab' | 'treeitem';
1623+
role?: Signalish<'button' | 'checkbox' | 'combobox' | 'gridcell' | 'link' | 'menuitem' | 'menuitemcheckbox' | 'menuitemradio' | 'option' | 'radio' | 'separator' | 'slider' | 'switch' | 'tab' | 'treeitem' | undefined>;
16241624
type?: Signalish<'submit' | 'reset' | 'button' | undefined>;
16251625
value?: Signalish<string | number | undefined>;
16261626
}
@@ -1653,7 +1653,7 @@ export namespace JSXInternal {
16531653
}
16541654

16551655
interface DataListHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
1656-
role?: 'listbox';
1656+
role?: Signalish<'listbox' | undefined>;
16571657
}
16581658

16591659
interface DdHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
@@ -1670,29 +1670,29 @@ export namespace JSXInternal {
16701670
extends HTMLAttributes<T> {
16711671
open?: Signalish<boolean | undefined>;
16721672
onToggle?: GenericEventHandler<T> | undefined;
1673-
role?: 'group';
1673+
role?: Signalish<'group' | undefined>;
16741674
}
16751675

16761676
interface DialogHTMLAttributes<T extends EventTarget>
16771677
extends HTMLAttributes<T> {
16781678
onCancel?: GenericEventHandler<T> | undefined;
16791679
onClose?: GenericEventHandler<T> | undefined;
16801680
open?: Signalish<boolean | undefined>;
1681-
role?: 'dialog' | 'alertdialog';
1681+
role?: Signalish<'dialog' | 'alertdialog' | undefined>;
16821682
}
16831683

16841684
interface DlHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
1685-
role?: 'group' | 'list' | 'none' | 'presentation';
1685+
role?: Signalish<'group' | 'list' | 'none' | 'presentation' | undefined>;
16861686
}
16871687

16881688
interface DtHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
1689-
role?: 'listitem';
1689+
role?: Signalish<'listitem' | undefined>;
16901690
}
16911691

16921692
interface EmbedHTMLAttributes<T extends EventTarget>
16931693
extends HTMLAttributes<T> {
16941694
height?: Signalish<number | string | undefined>;
1695-
role?: 'application' | 'document' | 'img' | 'none' | 'presentation';
1695+
role?: Signalish<'application' | 'document' | 'img' | 'none' | 'presentation' | undefined>;
16961696
src?: Signalish<string | undefined>;
16971697
type?: Signalish<string | undefined>;
16981698
width?: Signalish<number | string | undefined>;
@@ -1703,15 +1703,15 @@ export namespace JSXInternal {
17031703
disabled?: Signalish<boolean | undefined>;
17041704
form?: Signalish<string | undefined>;
17051705
name?: Signalish<string | undefined>;
1706-
role?: 'group'| 'none' | 'presentation' | 'radiogroup';
1706+
role?: Signalish<'group'| 'none' | 'presentation' | 'radiogroup' | undefined>;
17071707
}
17081708

17091709
interface FigcaptionHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
1710-
role?: 'group' | 'none' | 'presentation';
1710+
role?: Signalish<'group' | 'none' | 'presentation' | undefined>;
17111711
}
17121712

17131713
interface FooterHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
1714-
role?: 'contentinfo' | 'generic' | 'group' | 'none' | 'presentation' | 'doc-footnote';
1714+
role?: Signalish<'contentinfo' | 'generic' | 'group' | 'none' | 'presentation' | 'doc-footnote' | undefined>;
17151715
}
17161716

17171717
interface FormHTMLAttributes<T extends EventTarget>
@@ -1728,28 +1728,28 @@ export namespace JSXInternal {
17281728
novalidate?: Signalish<boolean | undefined>;
17291729
noValidate?: Signalish<boolean | undefined>;
17301730
rel?: Signalish<string | undefined>;
1731-
role?: 'form' | 'none' | 'presentation' | 'search';
1731+
role?: Signalish<'form' | 'none' | 'presentation' | 'search' | undefined>;
17321732
target?: Signalish<string | undefined>;
17331733
}
17341734

17351735
interface HeadingHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
1736-
role?: 'heading' | 'none' | 'presentation' | 'tab' | 'doc-subtitle';
1736+
role?: Signalish<'heading' | 'none' | 'presentation' | 'tab' | 'doc-subtitle' | undefined>;
17371737
}
17381738

17391739
interface HeadHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
17401740
role: never;
17411741
}
17421742

17431743
interface HeaderHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
1744-
role?: 'banner' | 'generic' | 'group' | 'none' | 'presentation';
1744+
role?: Signalish<'banner' | 'generic' | 'group' | 'none' | 'presentation' | undefined>;
17451745
}
17461746

17471747
interface HrHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
1748-
role?: 'separator' | 'none' | 'presentation' | 'doc-pagebreak';
1748+
role?: Signalish<'separator' | 'none' | 'presentation' | 'doc-pagebreak' | undefined>;
17491749
}
17501750

17511751
interface HtmlHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
1752-
role?: 'document';
1752+
role?: Signalish<'document' | undefined>;
17531753
}
17541754

17551755
interface IframeHTMLAttributes<T extends EventTarget>
@@ -1770,7 +1770,7 @@ export namespace JSXInternal {
17701770
name?: Signalish<string | undefined>;
17711771
referrerpolicy?: Signalish<HTMLAttributeReferrerPolicy | undefined>;
17721772
referrerPolicy?: Signalish<HTMLAttributeReferrerPolicy | undefined>;
1773-
role?: 'application' | 'document' | 'img' | 'none' | 'presentation';
1773+
role?: Signalish<'application' | 'document' | 'img' | 'none' | 'presentation' | undefined>;
17741774
sandbox?: Signalish<string | undefined>;
17751775
/** @deprecated */
17761776
scrolling?: Signalish<string | undefined>;
@@ -1938,7 +1938,7 @@ export namespace JSXInternal {
19381938
}
19391939

19401940
interface MainHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
1941-
role?: 'main';
1941+
role?: Signalish<'main' | undefined>;
19421942
}
19431943

19441944
interface MapHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
@@ -2005,12 +2005,12 @@ export namespace JSXInternal {
20052005
max?: Signalish<number | string | undefined>;
20062006
min?: Signalish<number | string | undefined>;
20072007
optimum?: Signalish<number | undefined>;
2008-
role?: 'meter';
2008+
role?: Signalish<'meter' | undefined>;
20092009
value?: Signalish<string | number | undefined>;
20102010
}
20112011

20122012
interface NavHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
2013-
role?: 'navigation' | 'menu' | 'menubar' | 'none' | 'presentation' | 'tablist';
2013+
role?: Signalish<'navigation' | 'menu' | 'menubar' | 'none' | 'presentation' | 'tablist' | undefined>;
20142014
}
20152015

20162016
interface NoScriptHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
@@ -2024,7 +2024,7 @@ export namespace JSXInternal {
20242024
form?: Signalish<string | undefined>;
20252025
height?: Signalish<number | string | undefined>;
20262026
name?: Signalish<string | undefined>;
2027-
role?: 'application' | 'document' | 'img';
2027+
role?: Signalish<'application' | 'document' | 'img' | undefined>;
20282028
type?: Signalish<string | undefined>;
20292029
usemap?: Signalish<string | undefined>;
20302030
useMap?: Signalish<string | undefined>;
@@ -2034,7 +2034,7 @@ export namespace JSXInternal {
20342034

20352035
interface OlHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
20362036
reversed?: Signalish<boolean | undefined>;
2037-
role?: 'list' | 'group' | 'listbox' | 'menu' | 'menubar' | 'none' | 'presentation' | 'radiogroup' | 'tablist' | 'toolbar' | 'tree';
2037+
role?: Signalish<'list' | 'group' | 'listbox' | 'menu' | 'menubar' | 'none' | 'presentation' | 'radiogroup' | 'tablist' | 'toolbar' | 'tree' | undefined>;
20382038
start?: Signalish<number | undefined>;
20392039
type?: Signalish<'1' | 'a' | 'A' | 'i' | 'I' | undefined>;
20402040
}
@@ -2043,14 +2043,14 @@ export namespace JSXInternal {
20432043
extends HTMLAttributes<T> {
20442044
disabled?: Signalish<boolean | undefined>;
20452045
label?: Signalish<string | undefined>;
2046-
role?: 'group';
2046+
role?: Signalish<'group' | undefined>;
20472047
}
20482048

20492049
interface OptionHTMLAttributes<T extends EventTarget>
20502050
extends HTMLAttributes<T> {
20512051
disabled?: Signalish<boolean | undefined>;
20522052
label?: Signalish<string | undefined>;
2053-
role?: 'option';
2053+
role?: Signalish<'option' | undefined>;
20542054
selected?: Signalish<boolean | undefined>;
20552055
value?: Signalish<string | number | undefined>;
20562056
}
@@ -2077,7 +2077,7 @@ export namespace JSXInternal {
20772077
interface ProgressHTMLAttributes<T extends EventTarget>
20782078
extends HTMLAttributes<T> {
20792079
max?: Signalish<number | string | undefined>;
2080-
role?: 'progressbar';
2080+
role?: Signalish<'progressbar' | undefined>;
20812081
value?: Signalish<string | number | undefined>;
20822082
}
20832083

@@ -2107,7 +2107,7 @@ export namespace JSXInternal {
21072107
}
21082108

21092109
interface SearchHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
2110-
role?: 'search' | 'form' | 'group' | 'none' | 'presentation' | 'region';
2110+
role?: Signalish<'search' | 'form' | 'group' | 'none' | 'presentation' | 'region' | undefined>;
21112111
}
21122112

21132113
interface SelectHTMLAttributes<T extends EventTarget>
@@ -2121,7 +2121,7 @@ export namespace JSXInternal {
21212121
name?: Signalish<string | undefined>;
21222122
required?: Signalish<boolean | undefined>;
21232123
// TODO: Select w/ multiple
2124-
role?: 'region' | 'generic' | 'alert' | 'alertdialog' | 'application' | 'banner' | 'complementary' | 'contentinfo' | 'dialog' | 'document' | 'feed' | 'group' | 'log' | 'main' | 'marquee' | 'navigation' | 'none' | 'note' | 'presentation' | 'search' | 'status' | 'tabpanel' | 'doc-abstract' | 'doc-acknowledgments' | 'doc-afterword' | 'doc-appendix' | 'doc-bibliography' | 'doc-chapter' | 'doc-colophon' | 'doc-conclusion' | 'doc-credit' | 'doc-credits' | 'doc-dedication' | 'doc-endnotes' | 'doc-epigraph' | 'doc-epilogue' | 'doc-errata' | 'doc-example' | 'doc-foreword' | 'doc-glossary' | 'doc-index' | 'doc-introduction' | 'doc-notice' | 'doc-pagelist' | 'doc-part' | 'doc-preface' | 'doc-prologue' | 'doc-pullquote' | 'doc-qna' | 'doc-toc';
2124+
role?: Signalish<'region' | 'generic' | 'alert' | 'alertdialog' | 'application' | 'banner' | 'complementary' | 'contentinfo' | 'dialog' | 'document' | 'feed' | 'group' | 'log' | 'main' | 'marquee' | 'navigation' | 'none' | 'note' | 'presentation' | 'search' | 'status' | 'tabpanel' | 'doc-abstract' | 'doc-acknowledgments' | 'doc-afterword' | 'doc-appendix' | 'doc-bibliography' | 'doc-chapter' | 'doc-colophon' | 'doc-conclusion' | 'doc-credit' | 'doc-credits' | 'doc-dedication' | 'doc-endnotes' | 'doc-epigraph' | 'doc-epilogue' | 'doc-errata' | 'doc-example' | 'doc-foreword' | 'doc-glossary' | 'doc-index' | 'doc-introduction' | 'doc-notice' | 'doc-pagelist' | 'doc-part' | 'doc-preface' | 'doc-prologue' | 'doc-pullquote' | 'doc-qna' | 'doc-toc' | undefined>;
21252125
size?: Signalish<number | undefined>;
21262126
value?: Signalish<string | number | undefined>;
21272127
onChange?: GenericEventHandler<T> | undefined;
@@ -2199,7 +2199,7 @@ export namespace JSXInternal {
21992199
placeholder?: Signalish<string | undefined>;
22002200
readOnly?: Signalish<boolean | undefined>;
22012201
required?: Signalish<boolean | undefined>;
2202-
role?: 'textbox';
2202+
role?: Signalish<'textbox' | undefined>;
22032203
rows?: Signalish<number | undefined>;
22042204
value?: Signalish<string | number | undefined>;
22052205
wrap?: Signalish<string | undefined>;
@@ -2240,7 +2240,7 @@ export namespace JSXInternal {
22402240
}
22412241

22422242
interface UlHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
2243-
role?: 'list' | 'group' | 'listbox' | 'menu' | 'menubar' | 'none' | 'presentation' | 'radiogroup' | 'tablist' | 'toolbar' | 'tree';
2243+
role?: Signalish<'list' | 'group' | 'listbox' | 'menu' | 'menubar' | 'none' | 'presentation' | 'radiogroup' | 'tablist' | 'toolbar' | 'tree' | undefined>;
22442244
}
22452245

22462246
interface VideoHTMLAttributes<T extends EventTarget>
@@ -2250,11 +2250,11 @@ export namespace JSXInternal {
22502250
width?: Signalish<number | string | undefined>;
22512251
disablePictureInPicture?: Signalish<boolean | undefined>;
22522252
disableRemotePlayback?: Signalish<boolean | undefined>;
2253-
role?: 'application';
2253+
role?: Signalish<'application' | undefined>;
22542254
}
22552255

22562256
interface WbrHTMLAttributes<T extends EventTarget> extends HTMLAttributes<T> {
2257-
role?: 'none' | 'presentation';
2257+
role?: Signalish<'none' | 'presentation' | undefined>;
22582258
}
22592259

22602260
export type DetailedHTMLProps<

test/ts/dom-attributes-test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ function createSignal<T>(value: T): JSX.SignalLike<T> {
1515
// @ts-expect-error A button should not have a role of presentation
1616
const badAriaRole = <button role="presentation" />;
1717
const validAriaRole = <button role="slider" />;
18+
const signalBadAriaRole = (
19+
// @ts-expect-error A button should not have a role of presentation
20+
<button role={createSignal('presentation' as const)} />
21+
)
22+
const signalValidAriaRole = (
23+
<button role={createSignal('slider' as const)} />
24+
)
1825

1926
// @ts-expect-error We should correctly type aria attributes like autocomplete
2027
const badAriaValues = <div aria-autocomplete="bad-value" />;

0 commit comments

Comments
 (0)