@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 -D
Usage
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";
const aria: PartiallyRequiredAriaTypes<"aria-atomic" | "role"> =
{
"aria-atomic": "true",
role: "alert"
};
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>;
<Component aria-atomic="true" role="alert">Component</Component>
<Component>Component</Component>
Packages
Ariatype is a bundle of multiple packages:
Resources