Remove orientation on dialog close
This commit is contained in:
@@ -37,6 +37,7 @@ export default class extends Controller {
|
||||
this.dialogTarget.close()
|
||||
this.dialogTarget.setAttribute('aria-hidden', 'true')
|
||||
this.dialogTarget.blur()
|
||||
orient(this.dialogTarget, false)
|
||||
}
|
||||
|
||||
closeOnClickOutside({ target }) {
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
const EDGE_THRESHOLD = 16
|
||||
|
||||
export function orient(el) {
|
||||
el.classList.toggle("orient-left", spaceOnRight(el) < EDGE_THRESHOLD)
|
||||
el.classList.toggle("orient-right", spaceOnLeft(el) < EDGE_THRESHOLD)
|
||||
el.classList.toggle("orient-top", spaceOnBottom(el) < EDGE_THRESHOLD)
|
||||
export function orient(el, orient = true) {
|
||||
const directions = [
|
||||
["orient-left", spaceOnRight],
|
||||
["orient-right", spaceOnLeft],
|
||||
["orient-top", spaceOnBottom]
|
||||
];
|
||||
|
||||
directions.forEach(([className, fn]) =>
|
||||
el.classList[orient && fn(el) < EDGE_THRESHOLD ? "add" : "remove"](className)
|
||||
);
|
||||
}
|
||||
|
||||
function spaceOnLeft(el) {
|
||||
|
||||
Reference in New Issue
Block a user