question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Datepicker pops up in modal but auto close when click on anything in the datepick menu

See original GitHub issue

I am using headless ui for modal dialog and the date picker is inside the modal. Initial focus is already set on the focusable button. When I click on the date picker component, it pops up the menu just fine, when I start to click anything on it, it closes.

Any advise?

Script setup code:

import { computed, reactive, ref } from 'vue';
import {
  TransitionRoot,
  TransitionChild,
  Dialog,
  DialogOverlay,
  DialogTitle,
} from '@headlessui/vue';
import { XIcon } from '@heroicons/vue/outline';
import PrimaryButton from '@/Components/Commons/PrimaryButton';

const props = defineProps({
  show: {
    type: Boolean,
    default: false,
  },
});

const emit = defineEmits(['hide', 'confirm']);

const form = reactive({
  starts_at: '',
  ends_at: '',
});

const closeButtonRef = ref(null);

const hide = () => emit('hide');

const confirm = () => {
  console.log('confirm');
};

Dialog(Modal) code:

<TransitionRoot as="template" :show="show">
    <Dialog @close="hide()"
            :initial-focus="closeButtonRef"
            as="div"
            class="fixed inset-0 z-10 overflow-hidden">
      <div class="absolute inset-0 overflow-hidden">
        <TransitionChild as="template"
                         enter="ease-in-out duration-300"
                         enter-from="opacity-0"
                         enter-to="opacity-100"
                         leave="ease-in-out duration-300"
                         leave-from="opacity-100"
                         leave-to="opacity-0">
          <DialogOverlay class="absolute inset-0 bg-black bg-opacity-70 transition-opacity" />
        </TransitionChild>

        <div class="fixed inset-y-0 right-0 max-w-full flex">
          <TransitionChild as="template"
                           enter="transform transition ease-in-out duration-300"
                           enter-from="translate-x-full"
                           enter-to="translate-x-0"
                           leave="transform transition ease-in-out duration-300"
                           leave-from="translate-x-0"
                           leave-to="translate-x-full">
            <div class="panel-width">
              <div class="h-full flex flex-col bg-white shadow-xl">
                <div class="min-h-0 flex-1 pb-12 flex flex-col gap-y-4 overflow-y-scroll">
                  <!-- Header -->
                  <div class="p-6 bg-gray-50">
                    <div class="flex items-start justify-between">

                      <!-- Title -->
                      <DialogTitle class="text-lg text-gray-900">
                        Create Skill Training
                      </DialogTitle>

                      <!-- Close Button -->
                      <div class="ml-3 h-7 flex items-center">
                        <button ref="closeButtonRef"
                                @click="hide()"
                                type="button"
                                class="rounded-md text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
                          <span class="sr-only">Close panel</span>
                          <XIcon class="h-6 w-6" aria-hidden="true" />
                        </button>
                      </div>
                    </div>
                  </div>

                  <!-- Content -->
                  <div class="mt-6 relative flex-1">
                    <form id="send-for-training-form" @submit.prevent="confirm()">
                      <section class="py-2 px-6 relative border border-red-500">

                        <!-- DATE PICKER HERE -->
                        <Datepicker v-model="form.starts_at" />

                      </section>
                    </form>
                  </div>
                </div>

                <!-- Footer -->
                <div class="flex flex-shrink-0 border-t border-gray-200 px-6 py-5">
                  <PrimaryButton type="submit" class="ml-auto">
                    Send For Training
                  </PrimaryButton>
                </div>
              </div>
            </div>
          </TransitionChild>
        </div>
      </div>
    </Dialog>
  </TransitionRoot>

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Jasenkoocommented, Apr 19, 2022

Great, version 3.2 will include some adjustments where you wouldn’t need to change the teleport target or add initial focus

0reactions
Jasenkoocommented, Aug 5, 2022

@donmb1 Will take a look

Read more comments on GitHub >

github_iconTop Results From Across the Web

jQuery Datepicker close datepicker after selected date
When I click to datepicker it opens and I select any date. My question: If I choose date from datepicker, I want to...
Read more >
DatePicker closes directly when used in Material-ui dialog
When I click the icon to toggle the DatePicker it just "bounces" or flashes, and is immediately closed. What could cause this behaviour?...
Read more >
DatePicker not closing when clicking outside #25135 - GitHub
Click on the button that opens the picker; Click outside of it. Context. I want the DatePicker to auto close when clicking outside....
Read more >
Datepicker in Angular using mat-datepicker | Material Design
Date picker is a component which allow users to choose a date from the calendar pop up or enter a date through text...
Read more >
Datepicker | Angular Material
Label for the button used to close the calendar popup. nextMonthLabel: 'Next month' ... Gets the element that the datepicker popup should be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found