This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/directives/focus.js

13 lines
461 B
JavaScript
Raw Normal View History

2020-11-02 20:52:07 +00:00
export default {
// When the bound element is inserted into the DOM...
mounted: (el, {modifiers}) => {
2020-11-02 20:52:07 +00:00
// Focus the element only if the viewport is big enough
// auto focusing elements on mobile can be annoying since in these cases the
// keyboard always pops up and takes half of the available space on the screen.
// The threshhold is the same as the breakpoints in css.
2021-12-10 12:21:25 +00:00
if (window.innerWidth > 769 || modifiers?.always) {
2020-11-02 20:52:07 +00:00
el.focus()
}
},
}