Move dialog focus handling into the dialog controller
... instead of a separate dialog focus controller
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
import { orient } from "helpers/orientation_helpers"
|
||||
import { isTouchDevice } from "helpers/platform_helpers"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = [ "dialog" ]
|
||||
static targets = [ "dialog", "focusMouse", "focusTouch" ]
|
||||
static values = {
|
||||
modal: { type: Boolean, default: false },
|
||||
sizing: { type: Boolean, default: true },
|
||||
@@ -10,6 +11,7 @@ export default class extends Controller {
|
||||
}
|
||||
|
||||
connect() {
|
||||
this.#setupFocus()
|
||||
this.dialogTarget.setAttribute("aria-hidden", "true")
|
||||
if (this.autoOpenValue) this.open()
|
||||
}
|
||||
@@ -63,4 +65,10 @@ export default class extends Controller {
|
||||
captureKey(event) {
|
||||
if (event.key !== "Escape") { event.stopPropagation() }
|
||||
}
|
||||
|
||||
#setupFocus() {
|
||||
const touch = isTouchDevice()
|
||||
if (this.hasFocusMouseTarget) this.focusMouseTarget.autofocus = !touch
|
||||
if (this.hasFocusTouchTarget) this.focusTouchTarget.autofocus = touch
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user