A custom HTML element which allows for arbitrary assignment of a set of string tags. This element may be used directly or subclassed to impose additional validation or functionality.

Hierarchy (view full)

Properties

_primaryInput: HTMLElement

The primary input (if any). Used to determine what element should receive focus when an associated label is clicked on.

_internals: ElementInternals

Attached ElementInternals which provides form handling functionality.

#button: HTMLButtonElement

The button element to add a new tag.

#input: HTMLInputElement

The input element to enter a new tag.

#tags: HTMLDivElement

The tags list of assigned tags.

#slug: boolean

Automatically slugify all strings provided to the element?

tagName: string = "string-tags"
formAssociated: boolean = true

Declare that this custom element provides form element functionality.

Accessors

  • get form(): HTMLFormElement
  • The form this element belongs to.

    Returns HTMLFormElement

  • get name(): string
  • The input element name.

    Returns string

  • get disabled(): boolean
  • Is this element disabled?

    Returns boolean

  • get editable(): boolean
  • Is this field editable? The field can be neither disabled nor readonly.

    Returns boolean

Methods

  • Internal

    Apply key attributes on the containing custom HTML element to input elements contained within it.

    Parameters

    • input: any

    Returns void

  • Protected

    Initialize innerText or an initial value attribute of the element as a comma-separated list of currently assigned string tags.

    Returns void

  • Protected

    Subclasses may impose more strict validation on what tags are allowed.

    Parameters

    • tag: string

      A candidate tag

    Returns void

    Throws

    An error if the candidate tag is not allowed

  • Protected

    Special handling when the custom element is clicked. This should be implemented to transfer focus to an appropriate internal element.

    Parameters

    • event: PointerEvent

    Returns void

  • Remove a tag from the set when its removal button is clicked.

    Parameters

    • event: PointerEvent

    Returns void

  • Add a tag to the set when the ENTER key is pressed in the text input.

    Parameters

    • event: KeyboardEvent

    Returns void

  • Add a new tag to the set upon user input.

    Returns void

  • Render the tagged string as an HTML element.

    Parameters

    • tag: string

      The raw tag value

    • Optional label: string

      An optional tag label

    • Optional editable: boolean = true

      Is the tag editable?

    Returns HTMLDivElement

    A rendered HTML element for the tag

  • Create a HTMLStringTagsElement using provided configuration data.

    Parameters

    • config: any

    Returns HTMLElement