Sha256: 2718ca9be3d3670e6b20e757d7d11af52c670928c64853770f2269c66d75a11d

Contents?: true

Size: 1.21 KB

Versions: 147

Compression:

Stored size: 1.21 KB

Contents

/* eslint-disable custom-elements/expose-class-on-global */
import {controller, targets} from '@github/catalyst'

@controller
export class PrimerMultiInputElement extends HTMLElement {
  @targets fields: HTMLInputElement[]

  activateField(name: string) {
    const fieldWithName = this.findField(name)
    if (!fieldWithName) return

    for (const field of this.fields) {
      if (field === fieldWithName) continue

      field.setAttribute('disabled', 'disabled')
      field.setAttribute('hidden', 'hidden')

      field.parentElement?.setAttribute('hidden', 'hidden')
    }

    fieldWithName.removeAttribute('disabled')
    fieldWithName.removeAttribute('hidden')
    fieldWithName.parentElement?.removeAttribute('hidden')
  }

  private findField(name: string): HTMLElement | null {
    for (const field of this.fields) {
      if (field.getAttribute('data-name') === name) {
        return field
      }
    }

    return null
  }
}

declare global {
  interface Window {
    PrimerMultiInputElement: typeof PrimerMultiInputElement
  }
}

if (!window.customElements.get('primer-multi-input')) {
  Object.assign(window, {PrimerMultiInputElement})
  window.customElements.define('primer-multi-input', PrimerMultiInputElement)
}

Version data entries

147 entries across 147 versions & 2 rubygems

Version Path
primer_view_components-0.30.0 lib/primer/forms/primer_multi_input.ts
openproject-primer_view_components-0.39.1 lib/primer/forms/primer_multi_input.ts
openproject-primer_view_components-0.39.0 lib/primer/forms/primer_multi_input.ts
openproject-primer_view_components-0.38.0 lib/primer/forms/primer_multi_input.ts
primer_view_components-0.29.0 lib/primer/forms/primer_multi_input.ts
primer_view_components-0.28.0 lib/primer/forms/primer_multi_input.ts
openproject-primer_view_components-0.37.1 lib/primer/forms/primer_multi_input.ts
openproject-primer_view_components-0.37.0 lib/primer/forms/primer_multi_input.ts
openproject-primer_view_components-0.36.2 lib/primer/forms/primer_multi_input.ts
openproject-primer_view_components-0.36.1 lib/primer/forms/primer_multi_input.ts
openproject-primer_view_components-0.36.0 lib/primer/forms/primer_multi_input.ts
primer_view_components-0.27.0 lib/primer/forms/primer_multi_input.ts
openproject-primer_view_components-0.35.2 lib/primer/forms/primer_multi_input.ts
openproject-primer_view_components-0.35.1 lib/primer/forms/primer_multi_input.ts
primer_view_components-0.26.1 lib/primer/forms/primer_multi_input.ts
openproject-primer_view_components-0.35.0 lib/primer/forms/primer_multi_input.ts
primer_view_components-0.26.0 lib/primer/forms/primer_multi_input.ts
openproject-primer_view_components-0.34.0 lib/primer/forms/primer_multi_input.ts
openproject-primer_view_components-0.33.2 lib/primer/forms/primer_multi_input.ts
openproject-primer_view_components-0.33.1 lib/primer/forms/primer_multi_input.ts