taga11y - v0.1.0
    Preparing search index...

    Class Taga11y

    Index

    Constructors

    • Creates a new taga11y instance and immediately initialises it.

      Parameters

      • input: HTMLInputElement

        The native <input> element to enhance.

      • options: Taga11yOptions = {}

        Configuration options for the widget.

      Returns Taga11y

      If suggestions defines both once and query keys.

    Accessors

    • get isOpen(): boolean

      Read-only property indicating whether the suggestion dropdown is currently visible.

      Returns boolean

    • get maxTagsReached(): boolean

      Read-only property indicating whether the maximum tag count has been reached (when maxTags is configured).

      Returns boolean

    • get tags(): TagData[]

      Read-only property returning the current tag array (defensive copy). Equivalent to getTags().

      Returns TagData[]

    Methods

    • Adds a single tag by value.

      Resolves the display label from loaded suggestions (matching on value), falling back to label === value if no match exists.

      Parameters

      • value: string

        The tag value to add.

      Returns boolean

      true if the tag was added; false if rejected (duplicate or max reached).

      Fires taga11y:add and taga11y:change on success. Fires no events on rejection (shows error chip + region instead).

    • Batch-adds multiple tags. Duplicates are skipped silently.

      Fires taga11y:add per successfully added tag and a single taga11y:change after all additions with the final tag set.

      Parameters

      Returns void

    • Blurs the combobox input element.

      Returns void

    • Removes all tags at once.

      Fires taga11y:clear (detail: { tags: TagData[] }) and taga11y:change (detail: { tags: [] }).

      Returns void

    • Closes the suggestion dropdown. No-op if already closed.

      Returns void

    • Tears down the widget: removes the injected DOM, detaches all event listeners, restores the original input's attributes, and moves it back to its original DOM position.

      Fires a taga11y:destroy event on the original input.

      Returns void

    • Dispatches a custom event on the original input element.

      All events bubble and are not cancelable.

      Parameters

      • event: string

        Event name.

      • data: Record<string, unknown>

        Event detail payload.

      Returns void

    • Focuses the combobox input element.

      Returns void

    • Returns a defensive copy of the current tag array.

      Returns TagData[]

      Array of TagData objects representing selected tags.

    • Initialises the widget: builds the DOM structure, wires up managers, pre-populates tags from the original input value, and sets up form reset handling.

      Called automatically by the constructor. Invoke again after destroy to re-initialise.

      Returns void

    • Checks whether a tag with the given value is currently selected.

      Parameters

      • value: string

        The tag value to check.

      Returns boolean

      true if a tag with the matching value exists.

    • Removes a previously registered event listener.

      Parameters

      • event: string

        Event name.

      • handler: EventListener

        The handler to remove.

      Returns void

    • Registers a listener for a taga11y custom event on the original input element.

      Parameters

      • event: string

        Event name. One of "taga11y:add", "taga11y:remove", "taga11y:clear", "taga11y:change", "taga11y:paste", or "taga11y:destroy". See the class docblock for detail payload shapes.

      • handler: EventListener

        Event listener callback.

      Returns void

    • Opens the suggestion dropdown. No-op if already open or disabled.

      Returns void

    • Removes a single tag by value.

      Parameters

      • value: string

        The tag value to remove.

      Returns TagData | null

      The removed TagData, or null if no tag with that value exists.

      Fires taga11y:remove and taga11y:change. Returns focus to the combobox input after removal.

    • Fully replaces all tags with the given items.

      Fires taga11y:clear with the previously selected tags, then taga11y:add per newly added tag, and finally a single taga11y:change with the final tag set.

      Parameters

      Returns void

    • Updates one or more runtime options after initialisation.

      Only the provided keys are applied; unprovided keys retain their current values. Each option triggers specific side effects:

      • disabled — enables/disables the input, hidden input, and chip remove buttons; toggles .taga11y--disabled class.
      • theme — sets or removes data-theme on the wrapper.
      • maxTags — updates the selection manager's limit.
      • delimiter — updates delimiter characters.
      • enforceSuggestions — toggles whitelist mode.
      • label — creates, updates, or removes the visible label element.
      • suggestions — replaces the suggestion source.
      • debounceMs — updates the debounce delay for dynamic mode.
      • serialize — updates the hidden input serializer.
      • deserialize — updates the initial-value parser; takes effect on the next form reset (does not retroactively re-parse current tags).
      • name — updates the hidden input's name attribute.

      Parameters

      • newOptions: Partial<Taga11yOptions>

        Partial options object with keys to update.

      Returns void