16 lines
498 B
TypeScript
16 lines
498 B
TypeScript
import type { Accessor } from "solid-js";
|
|
import { createSignal } from "solid-js";
|
|
|
|
/**
|
|
* Creates a reactive slot for an element's ID.
|
|
* Child parts (e.g. Dialog.Title) call setId on mount and clear it on cleanup.
|
|
* Parent parts (e.g. Dialog.Content) read getId to set aria-labelledby etc.
|
|
*/
|
|
export function createRegisterId(): [
|
|
Accessor<string | undefined>,
|
|
(id: string | undefined) => void,
|
|
] {
|
|
const [id, setId] = createSignal<string | undefined>(undefined);
|
|
return [id, setId];
|
|
}
|