@ariatype/ariatype
v1.0.1
Published
TypeScript type definitions for WAI-ARIA accessibility.
Downloads
7
Readme
@ariatype/ariatype
Ariatype provides TypeScript with complete type definitions for WAI-ARIA accessibility. The goal of this project is to further enhance developer experience and understanding of WAI-ARIA accessibility best practices.
Installation
npm install @ariatype/ariatype -D
Usage
import { AriaTypes } from "@ariatype/ariatype";
const aria: AriaTypes = {
"aria-atomic": "true",
role: "alert",
};
Requiring Aria Attributes
Use PartiallyRequiredAriaTypes
to require WAI-Attributes for a TypeScript type:
import type { PartiallyRequiredAriaTypes } from "@ariatype/ariatype";
// Valid
const aria: PartiallyRequiredAriaTypes<"aria-atomic" | "role"> = {
"aria-atomic": "true",
role: "alert",
};
// Invalid
// Property "aria-atomic" missing
const aria: PartiallyRequiredAriaTypes<"aria-atomic" | "role"> = {
role: "alert",
};
Example Use Case
The following example shows how Ariatype may be used to enforce type-safe WAI-ARIA attributes on a React component using PartiallyRequiredAriaTypes
:
import type { PartiallyRequiredAriaTypes } from "@ariatype/ariatype";
import type { ReactNode } from "react";
interface Props extends
PartiallyRequiredAriaTypes<"aria-atomic" | "role"> {
children: ReactNode;
};
export const Component = ({ children, ...props }: Props) =>
<div {...props}>{children}</div>;
// Valid
<Component aria-atomic="true" role="alert">Component</Component>
// Missing the following properties from type 'Props':
// "aria-atomic", role
<Component>Component</Component>
Packages
Ariatype is a bundle of multiple packages:
@ariatype/aria-attributes
:ariaAttributes
: all aria attributesAriaAttribute
: aria attribute typeAriaAttributes
: aria attributes type
@ariatype/aria-attributes-drag-and-drop
:ariaAttributesDragAndDrop
: all drag-and-drop aria attributesAriaAttributeDragAndDrop
: drag-and-drop aria attribute typeAriaAttributesDragAndDrop
: drag-and-drop aria attributes type
@ariatype/aria-attributes-global
:ariaAttributesGlobal
: all global aria attributesAriaAttributeGlobal
: global aria attribute typeAriaAttributesGlobal
: global aria attributes type
@ariatype/aria-attributes-live-region
:ariaAttributesLiveRegion
: all live region aria attributesAriaAttributeLiveRegion
: live region aria attribute typeAriaAttributesLiveRegion
: live region aria attributes type
@ariatype/aria-attributes-relationship
:ariaAttributesRelationship
: all relationship aria attributesAriaAttributeRelationship
: relationship aria attribute typeAriaAttributesRelationship
: relationship aria attributes type
@ariatype/aria-attributes-widget
:ariaAttributesWidget
: all widget aria attributesAriaAttributeWidget
: widget aria attribute typeAriaAttributesWidget
: widget aria attributes type
@ariatype/aria-roles
:ariaRoles
: all aria rolesAriaRole
: aria roles typeAriaRoles
: aria roles type
@ariatype/aria-roles-composite
:ariaRolesComposite
: all composite aria rolesAriaRoleComposite
: composite aria roles typeAriaRolesComposite
: composite aria roles type
@ariatype/aria-roles-document-structure
:ariaRolesDocumentStructure
: all document structure aria rolesAriaRoleDocumentStructure
: document structure aria roles typeAriaRolesDocumentStructure
: document structure aria roles type
@ariatype/aria-roles-generic
:ariaRolesGeneric
: all generic aria rolesAriaRoleGeneric
: generic aria roles typeAriaRolesGeneric
: generic aria roles type
@ariatype/aria-roles-landmark
:ariaRolesLandmark
: all landmark aria rolesAriaRoleLandmark
: landmark aria roles typeAriaRolesLandmark
: landmark aria roles type
@ariatype/aria-roles-live-region
:ariaRolesLiveRegion
: all live region aria rolesAriaRoleLiveRegion
: live region aria roles typeAriaRolesLiveRegion
: live region aria roles type
@ariatype/aria-roles-widget
:ariaRolesWidget
: all widget aria rolesAriaRoleWidget
: widget aria roles typeAriaRolesWidget
: widget aria roles type
@ariatype/aria-roles-window
:ariaRolesWindow
: all window aria rolesAriaRoleWindow
: window aria roles typeAriaRolesWindow
: window aria roles type