@svelkit/hooks
Version:
> common hooks for [svelte] (part of [svelkit])
35 lines (33 loc) • 1.14 kB
TypeScript
/**
* Autogenerate IDs to facilitate WAI-ARIA and server rendering.
*
* A string can be supplied as an argument to be autoId in lieu of the auto-generated ID.
* This is handy for accepting user-provided IDs that need to be deterministic.
*
* ```html
* <script>
* import { useAutoId } from '@sveltik/hooks'
*
* const autoId = useAutoId('my-component')
* </script>
*
* <label for={autoId('name')}>
* <input id={autoId('name')}>
*
* <label for={autoId('email')}>
* <input id={autoId('email')}>
* ```
*
* Some background:
* 1. Accessibiliy APIs rely heavily on element IDs
* 2. Requiring developers to put IDs on every element in is both
* cumbersome and error-prone
* 3. With a component model, we can generate IDs for them!
*
* **HTML5**: The value must be unique amongst all the IDs in the element's home subtree
* and must contain at least one character. The value must not contain any space characters.
*/
declare function useAutoId(base?: string): (name: string, ...args: unknown[]) => string;
//# sourceMappingURL=use-auto-id.d.ts.map
export { useAutoId };
//# sourceMappingURL=hooks.d.ts.map