Skip to content

Commit 93f0683

Browse files
committed
fix focus trap with the ok button
1 parent fcde90c commit 93f0683

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/components/TDatepicker.vue

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
:readonly="configuration.readonly"
4646
:placeholder="configuration.placeholder"
4747
v-bind="configuration.userInputAttributes"
48+
data-datepicker-focusable
4849
@input="userInputHandler"
4950
@focus="focusHandler"
5051
@blur="blurHandler"
@@ -310,7 +311,6 @@ export default defineComponent({
310311
// - Replace svg icons with icon component
311312
// - The click handler depnds of shown consider the case when using inline
312313
// - Consider using an undefined default value for togglin and, in cases like multiple or range keep the dropdown opened by default
313-
// - In multiple add an ok button
314314
// - Add a clear button
315315
const { configuration, attributes } = useConfigurationWithClassesList<TDatepickerOptions>(TDatepickerConfig, TDatepickerClassesKeys);
316316
const locale = useDateLocale({ configuration });
@@ -435,13 +435,22 @@ export default defineComponent({
435435
};
436436
437437
// If the date field is blurred (date clicked for example) we should focus
438-
// the field again
439-
// @TODO: Consider the case when other elements should keep the focus
440-
// like the eventual time picker
441-
const blurOnChildHandler = (e: Event) => {
438+
// the field again unless is a child element
439+
const blurOnChildHandler = (e: FocusEvent) => {
442440
const target = e.target as HTMLButtonElement | HTMLInputElement;
443441
444-
target.focus();
442+
const relatedTarget = e.relatedTarget as HTMLElement | EventTarget;
443+
const relatedTargetDataset: Data | undefined = relatedTarget instanceof HTMLElement
444+
? relatedTarget.dataset
445+
: undefined;
446+
447+
if (
448+
target.dataset.datepickerFocusable !== undefined
449+
&& relatedTargetDataset
450+
&& relatedTargetDataset.datepickerFocusable === undefined
451+
) {
452+
target.focus();
453+
}
445454
};
446455
447456
const keyboardNavigationHandler = (e: KeyboardEvent) => {

src/components/TDatepicker/DatepickerViewFooter.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<button
3131
type="button"
3232
class="text-blue-600 text-sm uppercase font-semibold transition duration-100 ease-in-out border border-transparent focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 rounded cursor-pointer ml-auto"
33+
data-datepicker-focusable
3334
@click="okButtonHandler"
3435
v-text="locale.okLabel"
3536
/>

0 commit comments

Comments
 (0)