-
Notifications
You must be signed in to change notification settings - Fork 43
Do not autofocus in iframes + other fixes. #778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
setFocus(target) { | ||
const $all = $(target); | ||
const visible = [...$all].filter((it) => $(it).is(":visible")); | ||
const empty = visible.filter((it) => it.value === ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pilz: this fix is for the documented behavior (in documentation.md + the index.html) to not autofocus if the input is not empty and there is another autofocus element.
src/pat/autofocus/autofocus.js
Outdated
// setFocus normally operates on the whole DOM anyways and if scoped | ||
// (via the event handler in init) the last one wins. | ||
// This is OK since only one element can have the focus. | ||
clearTimeout(scheduled_task); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pilz this is an optimization to call focus()
only once and not multiple times for each pat-autofocus element which can be found in the DOM.
$visible.get(0) && $visible.get(0).focus(); | ||
}, 10); | ||
|
||
if (!registered_event_handler) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pilz: We want the global event handler registered only once.
export default autofocus; | ||
setFocus(target) { | ||
// Exit if task is scheduled. setFocus operates on whole DOM anyways. | ||
if (scheduled_task) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pilz: If there is already a setFocus task scheduled, exit. No need to do it multiple times as this method operates on the whole DOM tree and is not scoped for the element itself.
|
||
init: function init() { | ||
init() { | ||
if (window.self !== window.top) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pilz: requested fix.
…d element, if there is another autofocus element which is empty.
Plus: