Sha256: 0aab5c3e979934d2a93482237e1b7c7e699cc00a853205675945209b90364414

Contents?: true

Size: 1.46 KB

Versions: 37

Compression:

Stored size: 1.46 KB

Contents

import '@github/auto-check-element'
import {controller, target} from '@github/catalyst'

// eslint-disable-next-line custom-elements/expose-class-on-global
@controller
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
class PrimerTextFieldElement extends HTMLElement {
  @target inputElement: HTMLInputElement
  @target validationElement: HTMLElement
  @target validationMessageElement: HTMLElement

  #abortController: AbortController | null

  connectedCallback(): void {
    this.#abortController?.abort()
    const {signal} = (this.#abortController = new AbortController())

    this.inputElement.addEventListener(
      'auto-check-success',
      () => {
        this.clearError()
      },
      {signal}
    )

    this.inputElement.addEventListener(
      'auto-check-error',
      async (event: any) => {
        const errorMessage = await event.detail.response.text()
        this.setError(errorMessage)
      },
      {signal}
    )
  }

  disconnectedCallback() {
    this.#abortController?.abort()
  }

  clearContents() {
    this.inputElement.value = ''
    this.inputElement.focus()
  }

  clearError(): void {
    this.inputElement.removeAttribute('invalid')
    this.validationElement.hidden = true
    this.validationMessageElement.textContent = ''
  }

  setError(message: string): void {
    this.validationMessageElement.textContent = message
    this.validationElement.hidden = false
    this.inputElement.setAttribute('invalid', 'true')
  }
}

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
openproject-primer_view_components-0.16.0 lib/primer/forms/primer_text_field.ts
openproject-primer_view_components-0.15.0 lib/primer/forms/primer_text_field.ts
openproject-primer_view_components-0.14.0 lib/primer/forms/primer_text_field.ts
openproject-primer_view_components-0.13.1 lib/primer/forms/primer_text_field.ts
primer_view_components-0.13.2 lib/primer/forms/primer_text_field.ts
primer_view_components-0.13.1 lib/primer/forms/primer_text_field.ts
openproject-primer_view_components-0.13.0 lib/primer/forms/primer_text_field.ts
primer_view_components-0.13.0 lib/primer/forms/primer_text_field.ts
primer_view_components-0.12.0 lib/primer/forms/primer_text_field.ts
primer_view_components-0.11.0 lib/primer/forms/primer_text_field.ts
openproject-primer_view_components-0.12.1 lib/primer/forms/primer_text_field.ts
primer_view_components-0.10.0 lib/primer/forms/primer_text_field.ts
openproject-primer_view_components-0.11.0 lib/primer/forms/primer_text_field.ts
openproject-primer_view_components-0.10.0 lib/primer/forms/primer_text_field.ts
primer_view_components-0.9.0 lib/primer/forms/primer_text_field.ts
openproject-primer_view_components-0.9.1 lib/primer/forms/primer_text_field.ts
openproject-primer_view_components-0.9.0 lib/primer/forms/primer_text_field.ts
openproject-primer_view_components-0.8.0 lib/primer/forms/primer_text_field.ts
primer_view_components-0.8.0 lib/primer/forms/primer_text_field.ts
primer_view_components-0.7.0 lib/primer/forms/primer_text_field.ts