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

iPhone closeOnSelection triggered by month and year dropdown #45

Open
hubert-ix opened this issue Jan 12, 2023 · 3 comments
Open

iPhone closeOnSelection triggered by month and year dropdown #45

hubert-ix opened this issue Jan 12, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@hubert-ix
Copy link

When a month or a year is selected, the whole calendar popup gets closed, which makes it impossible to select a date.

This seems to happen only on iPhones, it works fine on Android

@probablykasper probablykasper changed the title Month and year dropdown issue on iPhone iPhone closeOnSelection triggered by month and year dropdown Jan 12, 2023
@probablykasper
Copy link
Owner

I don't have an iPhone, so not sure I'll solve this when I can't reproduce it. Would appreciate a PR

@probablykasper probablykasper added the bug Something isn't working label Jan 18, 2023
@georgeemr
Copy link

Hi, the way we fix this issue was doing this change on the onFocusOut event:

function onFocusOut(e: FocusEvent) {
    if (
        e?.currentTarget instanceof HTMLElement &&
        e.relatedTarget &&
        e.relatedTarget instanceof Node &&
        e.currentTarget.contains(e.relatedTarget)
    ) {
        return;
    } else {
        if ($store !== null) {
            visible = false;
        }
    }
}

@probablykasper probablykasper linked a pull request May 29, 2023 that will close this issue
@akshat-angelone057
Copy link

akshat-angelone057 commented Feb 24, 2024

The way we have fixed it is by wrapping the DatePicker component inside a div and attaching a onFocusOut listener on the wrapper div and making visible true if the date is null/undefined

onMount(() => {
		if (/iP(hone|od|ad)/.test(navigator.userAgent) && /Safari/.test(navigator.userAgent)) {
			isIosSafari = true;
		}
	});

	const handleFocusOut = (event: Event) => {
		if (date == null && isIosSafari === true) {
			visible = true;
		}
	};
	
<div class="flex flex-col gap-2" on:focusout={handleFocusOut} {id}>
	<DateInput
		bind:value={date}
		{format}
		{placeholder}
		max={maxDate}
		min={minDate}
		{valid}
		{closeOnSelection}
		bind:visible
	/>
</div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants