2.0.0 • Published 10 months ago

@dddstack/ariatype v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

@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";

// 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:

Resources