Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby
683 B
Raw Blame
import { Controller } from "@hotwired/stimulus"

// Shows/hides the inline cost basis editor in the holding drawer.
// The total <-> per-share conversion lives in cost_basis_form_controller.
export default class extends Controller {
  static targets = ["form", "opener"]

  // Opening moves focus into the editor, closing (pencil or Cancel) returns it
  // to the pencil, so focus never drops to <body> with the hidden form.
  toggle(event) {
    event.preventDefault()
    const hidden = this.formTarget.classList.toggle("hidden")

    if (hidden) {
      this.openerTarget.focus()
    } else {
      this.formTarget.querySelector("input:not([type='hidden'])")?.focus()
    }
  }
}