mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
refactor(datepicker): optimize focus handling and improve calendar positioning logic
This commit is contained in:
1 parent
a1e71006f0
commit
3e130c9a0d
3 files changed
+102
-183
No files matched your search
@@ -10,19 +10,9 @@ export default {
|
||||
methods: {
|
||||
setFocusEvent() {
|
||||
const inputs = document.querySelectorAll('.v-autocomplete input');
|
||||
console.log(
|
||||
'🟢 [VuetifyFixFocusMixin] setFocusEvent - Found',
|
||||
inputs.length,
|
||||
'autocomplete inputs',
|
||||
);
|
||||
inputs.forEach((input) => {
|
||||
input.addEventListener('focus', this.onInputFocus);
|
||||
});
|
||||
console.log(
|
||||
'🟢 [VuetifyFixFocusMixin] Attached focus listeners to',
|
||||
inputs.length,
|
||||
'inputs',
|
||||
);
|
||||
},
|
||||
|
||||
onDateFocus($event) {
|
||||
@@ -32,53 +22,26 @@ export default {
|
||||
},
|
||||
|
||||
onDateOpen($event) {
|
||||
console.log(
|
||||
'🟢 [VuetifyFixFocusMixin] onDateOpen called at:',
|
||||
new Date().toISOString(),
|
||||
'with event:',
|
||||
$event,
|
||||
);
|
||||
// $event should be the element reference (or any truthy value to trigger saving)
|
||||
if ($event) {
|
||||
// Find the scrollable modal container
|
||||
const modalContent = document.querySelector('.v-dialog .modal-content');
|
||||
if (modalContent) {
|
||||
this.savedScrollPosition = modalContent.scrollTop;
|
||||
console.log(
|
||||
'🟢 [VuetifyFixFocusMixin] Saved scroll position:',
|
||||
this.savedScrollPosition,
|
||||
);
|
||||
} else {
|
||||
console.log('🟢 [VuetifyFixFocusMixin] Modal content not found');
|
||||
}
|
||||
|
||||
this.preventInputFocus = true;
|
||||
console.log(
|
||||
'🟢 [VuetifyFixFocusMixin] preventInputFocus set to:',
|
||||
this.preventInputFocus,
|
||||
);
|
||||
|
||||
// Reset after datepicker is opened
|
||||
setTimeout(() => {
|
||||
this.preventInputFocus = false;
|
||||
this.savedScrollPosition = null;
|
||||
console.log(
|
||||
'🟢 [VuetifyFixFocusMixin] Reset preventInputFocus and savedScrollPosition after 500ms',
|
||||
);
|
||||
}, 500);
|
||||
}
|
||||
},
|
||||
|
||||
onInputFocus($event) {
|
||||
const target = $event.target;
|
||||
console.log('🟢 [VuetifyFixFocusMixin] onInputFocus triggered on:', {
|
||||
tagName: target.tagName,
|
||||
type: target.type,
|
||||
id: target.id,
|
||||
className: target.className,
|
||||
preventInputFocus: this.preventInputFocus,
|
||||
savedScrollPosition: this.savedScrollPosition,
|
||||
});
|
||||
|
||||
// If we have a saved scroll position and an unwanted focus happened
|
||||
if (this.preventInputFocus && this.savedScrollPosition !== null) {
|
||||
@@ -86,14 +49,9 @@ export default {
|
||||
|
||||
// Only intercept text input focus (autocomplete fields)
|
||||
if (target.tagName === 'INPUT' && target.type === 'text') {
|
||||
console.log('🟢 [VuetifyFixFocusMixin] PREVENTING FOCUS on:', target);
|
||||
const scrollBefore = document.querySelector(
|
||||
'.v-dialog .modal-content',
|
||||
)?.scrollTop;
|
||||
console.log(
|
||||
'🟢 [VuetifyFixFocusMixin] Scroll position before:',
|
||||
scrollBefore,
|
||||
);
|
||||
|
||||
// Blur the focused element
|
||||
setTimeout(() => {
|
||||
@@ -105,25 +63,9 @@ export default {
|
||||
if (modalContent && this.savedScrollPosition !== null) {
|
||||
modalContent.scrollTop = this.savedScrollPosition;
|
||||
const scrollAfter = modalContent.scrollTop;
|
||||
console.log(
|
||||
'🟢 [VuetifyFixFocusMixin] Scroll position restored to:',
|
||||
scrollAfter,
|
||||
);
|
||||
}
|
||||
}, 0);
|
||||
} else {
|
||||
console.log(
|
||||
'🟢 [VuetifyFixFocusMixin] Not a text input, skipping prevention',
|
||||
);
|
||||
}
|
||||
} else {
|
||||
console.log(
|
||||
'🟢 [VuetifyFixFocusMixin] Focus allowed (preventInputFocus:',
|
||||
this.preventInputFocus,
|
||||
', savedScrollPosition:',
|
||||
this.savedScrollPosition,
|
||||
')',
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
@@ -505,12 +505,6 @@ export default {
|
||||
methods: {
|
||||
// Override onDateOpen from VuetifyFixFocusMixin to add logging
|
||||
onDateOpen($event) {
|
||||
console.log(
|
||||
'🟡 [z-task-modal] onDateOpen called at:',
|
||||
new Date().toISOString(),
|
||||
'with event:',
|
||||
$event,
|
||||
);
|
||||
// Call the parent mixin's onDateOpen method
|
||||
if (
|
||||
VuetifyFixFocusMixin.methods &&
|
||||
@@ -523,17 +517,6 @@ export default {
|
||||
// Override onInputFocus from VuetifyFixFocusMixin to add logging
|
||||
onInputFocus($event) {
|
||||
const target = $event?.target;
|
||||
console.log(
|
||||
'🟡 [z-task-modal] onInputFocus called at:',
|
||||
new Date().toISOString(),
|
||||
'on:',
|
||||
{
|
||||
tagName: target?.tagName,
|
||||
type: target?.type,
|
||||
id: target?.id,
|
||||
className: target?.className,
|
||||
},
|
||||
);
|
||||
// Call the parent mixin's onInputFocus method
|
||||
if (
|
||||
VuetifyFixFocusMixin.methods &&
|
||||
@@ -601,9 +584,6 @@ export default {
|
||||
|
||||
// CRITICAL: Prevent v-dialog autofocus BEFORE modal opens
|
||||
this.preventInputFocus = true;
|
||||
console.log(
|
||||
'🟡 [z-task-modal] showModal - preventInputFocus set to true BEFORE modal opens',
|
||||
);
|
||||
|
||||
this.visible = true;
|
||||
this.timeblocks = [
|
||||
@@ -620,9 +600,6 @@ export default {
|
||||
// Reset after modal is fully rendered and v-dialog autofocus has been blocked
|
||||
setTimeout(() => {
|
||||
this.preventInputFocus = false;
|
||||
console.log(
|
||||
'🟡 [z-task-modal] showModal - preventInputFocus reset to false after 300ms',
|
||||
);
|
||||
}, 300);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user