Skip to content
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

Fix PDateInput closing when picking a month or year #1314

Merged
merged 3 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/Calendar/PCalendarDatePicker.vue
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated linting fix

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<script lang="ts" setup>
import { eachDayOfInterval, endOfMonth, endOfWeek, format, isSameDay, isSameMonth, isToday, startOfMonth, startOfWeek } from 'date-fns'
import { computed } from 'vue'
import { VNode, computed } from 'vue'
import { ClassValue } from '@/types/attributes'
import { isDateAfter, isDateBefore, isNotNullish } from '@/utilities'

Expand All @@ -55,7 +55,7 @@
}>()

defineSlots<{
date: (props: DateSlotScope) => any,
date: (props: DateSlotScope) => VNode,
}>()

const selected = computed({
Expand Down
33 changes: 31 additions & 2 deletions src/components/PopOver/PPopOver.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import { useMostVisiblePositionStyles } from '@/compositions/position'
import { usePopOverGroup } from '@/compositions/usePopOverGroup'
import { PositionMethod } from '@/types/position'
import { randomId } from '@/utilities'
import { isDefined, randomId } from '@/utilities'

Check warning on line 26 in src/components/PopOver/PPopOver.vue

View workflow job for this annotation

GitHub Actions / ESLint

'isDefined' is defined but never used

Check warning on line 26 in src/components/PopOver/PPopOver.vue

View workflow job for this annotation

GitHub Actions / ESLint

'isDefined' is defined but never used
import { left, right, bottom, top } from '@/utilities/position'

const props = withDefaults(defineProps<{
Expand Down Expand Up @@ -72,11 +72,20 @@

function eventHandler(event: MouseEvent | FocusEvent): void {
const eventTarget = event.target as Element

const isMouseEvent = event instanceof MouseEvent

/*
* isEventInElement checks are backup checks for click events where the
* click changes the content of the popover. The element clicked on may
* no longer exist in the dom so the element.contains check will fail.
* So falling back to checking if the event x,y originated within the element
*/
if (
!props.autoClose
|| target.value?.contains(eventTarget)
|| isMouseEvent && isEventInElement(event, target.value)
|| content.value?.contains(eventTarget)
|| isMouseEvent && isEventInElement(event, content.value)
|| eventTarget.closest('.p-pop-over-content') !== null
) {
return
Expand All @@ -85,6 +94,26 @@
close()
}

function isEventInElement(event: MouseEvent, element: Element | undefined): boolean {
if (!element) {
return false
}

const rect = element.getBoundingClientRect()
const { clientX, clientY } = event

if (clientX < rect.left || clientX >= rect.right) {
return false
}

if (clientY < rect.top || clientY >= rect.bottom) {
return false
}

return true
}


function open(): void {
setGroupCloseMethod(close)

Expand Down
6 changes: 3 additions & 3 deletions src/components/VirtualScroller/PVirtualScrollerChunk.vue
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated linting fix

Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
}>()

const styles = computed(() => ({
height: visible.value ? undefined : `${height.value ?? props.height}px`,
height: visible.value ? undefined : `${internalHeight.value ?? props.height}px`,
}))

const el = ref<HTMLDivElement>()
const visible = ref(false)
const height = ref<number | null>(null)
const internalHeight = ref<number | null>(null)
const { observe } = useIntersectionObserver(intersect, props.observerOptions)

function setHeight(): void {
setTimeout(() => {
const rect = el.value!.getBoundingClientRect()

height.value = rect.height
internalHeight.value = rect.height
})
}

Expand Down
Loading