├── .prettierignore
├── .editorconfig
├── src
├── utils.ts
├── index.ts
├── toolbar
│ ├── README.md
│ └── toolbar.ts
├── accordion
│ ├── accordion.ts
│ └── README.md
├── tabs
│ ├── README.md
│ └── tabs.ts
├── disclosure
│ ├── README.md
│ └── disclosure.ts
├── menu
│ ├── README.md
│ └── menu.ts
├── tooltip
│ ├── README.md
│ └── tooltip.ts
├── popup
│ ├── README.md
│ └── popup.ts
├── alerts
│ ├── README.md
│ └── alerts.ts
└── modal
│ ├── README.md
│ └── modal.ts
├── tsconfig.json
├── vite.config.js
├── LICENSE
├── README.md
├── package.json
├── index.html
└── CHANGELOG.md
/.prettierignore:
--------------------------------------------------------------------------------
1 | dist
2 | CHANGELOG.md
3 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | end_of_line = lf
6 | insert_final_newline = true
7 | indent_style = space
8 | indent_size = 4
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | trim_trailing_whitespace = false
13 |
14 | [*.{html,less,css,yml}]
15 | indent_size = 2
16 |
--------------------------------------------------------------------------------
/src/utils.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Determine whether the user is trying to open a link in a new tab.
3 | */
4 | export function shouldOpenInNewTab(e: MouseEvent): boolean {
5 | return (
6 | e.altKey ||
7 | e.ctrlKey ||
8 | e.metaKey ||
9 | e.shiftKey ||
10 | (e.button !== undefined && e.button !== 0)
11 | );
12 | }
13 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | export { default as AccordionElement } from './accordion/accordion';
2 | export { default as AlertsElement } from './alerts/alerts';
3 | export { default as DisclosureElement } from './disclosure/disclosure';
4 | export { default as MenuElement } from './menu/menu';
5 | export { default as ModalElement } from './modal/modal';
6 | export { default as PopupElement } from './popup/popup';
7 | export { default as TabsElement } from './tabs/tabs';
8 | export { default as ToolbarElement } from './toolbar/toolbar';
9 | export { default as TooltipElement } from './tooltip/tooltip';
10 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ESNext",
4 | "useDefineForClassFields": true,
5 | "module": "ESNext",
6 | "lib": ["ESNext", "DOM", "DOM.Iterable"],
7 | "moduleResolution": "Node",
8 | "strict": true,
9 | "sourceMap": true,
10 | "resolveJsonModule": true,
11 | "isolatedModules": true,
12 | "esModuleInterop": true,
13 | "noUnusedLocals": true,
14 | "noImplicitReturns": true,
15 | "skipLibCheck": true,
16 | "declaration": true,
17 | "declarationDir": "dist/types"
18 | },
19 | "include": ["src"]
20 | }
21 |
--------------------------------------------------------------------------------
/vite.config.js:
--------------------------------------------------------------------------------
1 | import { resolve } from 'path';
2 | import { defineConfig } from 'vite';
3 |
4 | export default defineConfig({
5 | build: {
6 | lib: {
7 | entry: resolve(__dirname, 'src/index.ts'),
8 | formats: ['es'],
9 | fileName: 'inclusive-elements',
10 | },
11 | rollupOptions: {
12 | external: [
13 | '@floating-ui/dom',
14 | 'focus-trap',
15 | 'hello-goodbye',
16 | 'tabbable',
17 | ],
18 | output: {
19 | preserveModules: true,
20 | },
21 | },
22 | },
23 | });
24 |
--------------------------------------------------------------------------------
/src/toolbar/README.md:
--------------------------------------------------------------------------------
1 | # Toolbar
2 |
3 | **A custom element for building accessible toolbars.**
4 |
5 | A toolbar is a container for grouping a set of controls, such as buttons, menubuttons, or checkboxes.
6 |
7 | ## Example
8 |
9 | ```js
10 | import { ToolbarElement } from 'inclusive-elements';
11 |
12 | window.customElements.define('ui-toolbar', ToolbarElement);
13 | ```
14 |
15 | ```html
16 |
17 |
18 |
19 |
20 |
21 | ```
22 |
23 | ## Behavior
24 |
25 | - The `` element will be given a role of `toolbar`.
26 |
27 | - Focus management is implemented so the keyboard tab sequence includes one stop for the toolbar, and the Left Arrow, Right Arrow, Home, and End keys move focus among the controls in the toolbar.
28 |
29 | ## Further Reading
30 |
31 | - [ARIA Authoring Practices Guide: Toolbar Pattern](https://www.w3.org/WAI/ARIA/apg/patterns/toolbar/)
32 |
--------------------------------------------------------------------------------
/src/accordion/accordion.ts:
--------------------------------------------------------------------------------
1 | import DisclosureElement from '../disclosure/disclosure';
2 |
3 | export default class AccordionElement extends HTMLElement {
4 | public connectedCallback(): void {
5 | this.addEventListener('toggle', this.onToggle, { capture: true });
6 | }
7 |
8 | public disconnectedCallback(): void {
9 | this.removeEventListener('toggle', this.onToggle, { capture: true });
10 | }
11 |
12 | private onToggle = (e: Event) => {
13 | const target = e.target as DisclosureElement | HTMLDetailsElement;
14 | if (!target.open) return;
15 | this.querySelectorAll(
16 | ':scope > :is(ui-disclosure, details)'
17 | ).forEach((el) => {
18 | el.toggleAttribute('open', el === target);
19 | if (this.required) {
20 | el.toggleAttribute('disabled', el === target);
21 | }
22 | });
23 | };
24 |
25 | get required() {
26 | return this.hasAttribute('required');
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) Toby Zerner
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/accordion/README.md:
--------------------------------------------------------------------------------
1 | # Accordion
2 |
3 | **A custom element for building accessible accordions.**
4 |
5 | The accordion element wraps multiple disclosure elements, and ensures only one of these is expanded at a time.
6 |
7 | ## Example
8 |
9 | ```js
10 | import { AccordionElement } from 'inclusive-elements';
11 |
12 | window.customElements.define('ui-accordion', AccordionElement);
13 | ```
14 |
15 | ```html
16 |
17 |
18 |
19 |
20 |
21 |
22 | Details
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | Details
32 |
33 |
34 |
35 | ```
36 |
37 | ## Behavior
38 |
39 | - Whenever a direct child `` or `` element is opened, sibling `` and `` elements will be closed.
40 |
41 | - If the `required` attribute is present, the `` element that is currently open will be `disabled`.
42 |
43 | ## Further Reading
44 |
45 | - [ARIA Authoring Practices Guide: Accordion Pattern](https://www.w3.org/WAI/ARIA/apg/patterns/accordion/)
46 |
--------------------------------------------------------------------------------
/src/tabs/README.md:
--------------------------------------------------------------------------------
1 | # Tabs
2 |
3 | **A custom element for building accessible tabbed interfaces.**
4 |
5 | ## Example
6 |
7 | ```js
8 | import { TabsElement } from 'inclusive-elements';
9 |
10 | window.customElements.define('ui-tabs', TabsElement);
11 | ```
12 |
13 | ```html
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Tab Panel 1
21 |
Tab Panel 2
22 |
Tab Panel 3
23 |
24 | ```
25 |
26 | ## Behavior
27 |
28 | - Descendants with `role="tab"` and `role="tabpanel"` will have appropriate `id`, `aria-controls`, and `aria-labelledby` attributes generated if they are not already set.
29 |
30 | - The active `tab` will have the `aria-selected="true"` attribute set. Inactive tabs will have their `tabindex` set to `-1` so that focus remains on the active tab.
31 |
32 | - When focus is on the active `tab`, pressing the `Left Arrow`, `Right Arrow`, `Home`, and `End` keys can be used for navigation. If the `tablist` has `aria-orientation="vertical"`, `Down Arrow` and `Up Arrow` are used instead.
33 |
34 | - The `tab` with focus is automatically activated, and its corresponding `tabpanel` will become visible.
35 |
36 | ## Further Reading
37 |
38 | - [ARIA Authoring Practices Guide: Tabs Pattern](https://www.w3.org/WAI/ARIA/apg/patterns/tabs/)
39 |
--------------------------------------------------------------------------------
/src/disclosure/README.md:
--------------------------------------------------------------------------------
1 | # Disclosure Widget
2 |
3 | **A custom element for building accessible disclosure widgets.**
4 |
5 | ## Example
6 |
7 | ```js
8 | import { DisclosureElement } from 'inclusive-elements';
9 |
10 | window.customElements.define('ui-disclosure', DisclosureElement);
11 | ```
12 |
13 | ```html
14 |
15 |
16 |
Details
17 |
18 | ```
19 |
20 | ## Behavior
21 |
22 | - The first descendant that is a `