Sha256: f7d6a7b9ab22963aca25593343c178b918c98b4f13ba568e105c335b7138c156
Contents?: true
Size: 899 Bytes
Versions: 31
Compression:
Stored size: 899 Bytes
Contents
import { Controller } from "@hotwired/stimulus" const BOTTOM_THRESHOLD = 0 export default class extends Controller { static targets = [ "button", "menu" ] static classes = [ "flip" ] show() { this.menuTarget.show() this.#updateExpanded() this.#orient() } close() { this.menuTarget.close() this.#updateExpanded() } toggle() { this.menuTarget.open ? this.close() : this.show() } closeOnClickOutside({ target }) { !this.element.contains(target) && this.close() } #orient() { this.menuTarget.classList.toggle(this.flipClass, this.#distanceToBottom < BOTTOM_THRESHOLD) } #updateExpanded() { this.buttonTarget.ariaExpanded = this.menuTarget.open } get #distanceToBottom() { return window.innerHeight - this.#boundingClientRect.bottom } get #boundingClientRect() { return this.menuTarget.getBoundingClientRect() } }
Version data entries
31 entries across 31 versions & 1 rubygems