2.0.0 • Published 2 years ago
@dddstack/ariatype v2.0.0
@dddstack/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 @dddstack/ariatype -DUsage
import { AriaTypes } from "@dddstack/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 "@dddstack/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 "@dddstack/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:
@dddstack/ariatype-aria-attributes:ariaAttributes: all aria attributesAriaAttribute: aria attribute typeAriaAttributes: aria attributes type
@dddstack/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
@dddstack/ariatype-aria-attributes-global:ariaAttributesGlobal: all global aria attributesAriaAttributeGlobal: global aria attribute typeAriaAttributesGlobal: global aria attributes type
@dddstack/ariatype-aria-attributes-live-region:ariaAttributesLiveRegion: all live region aria attributesAriaAttributeLiveRegion: live region aria attribute typeAriaAttributesLiveRegion: live region aria attributes type
@dddstack/ariatype-aria-attributes-relationship:ariaAttributesRelationship: all relationship aria attributesAriaAttributeRelationship: relationship aria attribute typeAriaAttributesRelationship: relationship aria attributes type
@dddstack/ariatype-aria-attributes-widget:ariaAttributesWidget: all widget aria attributesAriaAttributeWidget: widget aria attribute typeAriaAttributesWidget: widget aria attributes type
@dddstack/ariatype-aria-roles:ariaRoles: all aria rolesAriaRole: aria roles typeAriaRoles: aria roles type
@dddstack/ariatype-aria-roles-composite:ariaRolesComposite: all composite aria rolesAriaRoleComposite: composite aria roles typeAriaRolesComposite: composite aria roles type
@dddstack/ariatype-aria-roles-document-structure:ariaRolesDocumentStructure: all document structure aria rolesAriaRoleDocumentStructure: document structure aria roles typeAriaRolesDocumentStructure: document structure aria roles type
@dddstack/ariatype-aria-roles-generic:ariaRolesGeneric: all generic aria rolesAriaRoleGeneric: generic aria roles typeAriaRolesGeneric: generic aria roles type
@dddstack/ariatype-aria-roles-landmark:ariaRolesLandmark: all landmark aria rolesAriaRoleLandmark: landmark aria roles typeAriaRolesLandmark: landmark aria roles type
@dddstack/ariatype-aria-roles-live-region:ariaRolesLiveRegion: all live region aria rolesAriaRoleLiveRegion: live region aria roles typeAriaRolesLiveRegion: live region aria roles type
@dddstack/ariatype-aria-roles-widget:ariaRolesWidget: all widget aria rolesAriaRoleWidget: widget aria roles typeAriaRolesWidget: widget aria roles type
@dddstack/ariatype-aria-roles-window:ariaRolesWindow: all window aria rolesAriaRoleWindow: window aria roles typeAriaRolesWindow: window aria roles type