0.5.2 • Published 5 months ago

invokers-polyfill v0.5.2

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

Invoker Buttons Polyfill

This polyfills the HTML commandfor/command attributes, as proposed by the Open UI group.

To see the explainer of these, please visit https://open-ui.org/components/invokers.explainer/.

Installation

With npm

If you're using npm, you only need to import the package, like so:

import "invokers-polyfill";

This will automatically apply the polyfill if required.

If you'd like to manually apply the polyfill, you can instead import the isSupported and apply functions directly from the ./invoker.js file, which is mapped to /fn:

import { isSupported, apply } from "invokers-polyfill/fn";
if (!isSupported()) apply();

An isPolyfilled function is also available, to detect if it has been polyfilled:

import { isSupported, isPolyfilled, apply } from "invokers-polyfill/fn";
if (!isSupported() && !isPolyfilled()) apply();

Alternatively, if you're not using a package manager, you can use the unpkg script:

<!-- polyfill automatically -->
<script
  type="module"
  async
  src="https://unpkg.com/invokers-polyfill@latest/invoker.min.js"
></script>
<!-- polyfill manually -->
<script type="module" async>
  import {isSupported, apply} from "https://unpkg.com/invokers-polyfill@latest/invoker.js"
  if (!isSupported()) apply();
  >
</script>

Usage

With the module imported, you can add commandfor and command attributes to your HTML:

<button commandfor="my-dialog" command="show-modal">Open Dialog!</button>
<dialog id="my-dialog">I'm a dialog!</dialog>

Limitations

This polyfill does not handle the aria (e.g. aria-expanded) of the command button the way browsers do. You are strongly encouraged to handle this state yourself, to ensure your site is accessible.

0.4.9

5 months ago

0.4.8

5 months ago

0.4.7

5 months ago

0.5.0

5 months ago

0.5.2

5 months ago

0.5.1

5 months ago

0.4.6

9 months ago

0.4.5

11 months ago

0.4.4

11 months ago

0.4.1

12 months ago

0.4.3

11 months ago

0.4.2

12 months ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.4

1 year ago

0.1.5

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

2 years ago