Sha256: ab96b86f261e1a99de38556bc073e34a7012447f9a3f0e6f9d9959192b00bc34

Contents?: true

Size: 1.23 KB

Versions: 11

Compression:

Stored size: 1.23 KB

Contents

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

@controller
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',
      (event: any) => {
        event.detail.response.text().then(
          (error_message: string) => { this.setError(error_message) }
        )
      },
      {signal}
    )
  }

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

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

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
primer_view_components-0.1.1 lib/primer/forms/primer_text_field.ts
primer_view_components-0.1.0 lib/primer/forms/primer_text_field.ts
primer_view_components-0.0.123 lib/primer/forms/primer_text_field.ts
primer_view_components-0.0.122 lib/primer/forms/primer_text_field.ts
primer_view_components-0.0.121 lib/primer/forms/primer_text_field.ts
primer_view_components-0.0.120 lib/primer/forms/primer_text_field.ts
primer_view_components-0.0.119 lib/primer/forms/primer_text_field.ts
primer_view_components-0.0.118 lib/primer/forms/primer_text_field.ts
primer_view_components-0.0.117 lib/primer/forms/primer_text_field.ts
primer_view_components-0.0.116 lib/primer/forms/primer_text_field.ts
primer_view_components-0.0.115 lib/primer/forms/primer_text_field.ts