Skip to content

Selecting a day takes one click while the text box has focus - #163

Open
grafst wants to merge 1 commit into
coolsam726:mainfrom
blemli:fix/calendar-click-while-input-focused
Open

grafst wants to merge 1 commit into
coolsam726:mainfrom
blemli:fix/calendar-click-while-input-focused

Conversation

@grafst

@grafst grafst commented Nov 12, 2026

Copy link
Copy Markdown

Problem

With ->allowInput(), a day in the calendar has to be clicked twice when the text box has focus (which it has right after opening the picker by clicking into the field).

Clicking a day blurs the (alt) input first. bindManualInputEvents() commits the typed text on that blur: fp.clear() for an empty box, fp.setDate() otherwise. Both redraw the calendar between mousedown and mouseup, so the click lands on an element that is no longer in the document and nothing gets selected. The second click works because the input is no longer focused.

To reproduce: a Flatpickr::make('day')->allowInput() field, click into the empty field, click a day once.

Fix

While the pointer is down inside the calendar, or focus moves into it, the blur handler leaves the value alone; the selection (or onClose) commits it. Typing a date and leaving the field elsewhere commits exactly as before.

resources/dist/components/flatpickr.js is rebuilt with npm run build:scripts; no other built file changed.

Verification

I ran the old and the new bundle through the same sequence in jsdom (mousedown on a day, blur on the alt input, mouseup, click):

clicked day still in the document after the blur selected after one click
before no no
after yes yes

A typed date followed by a normal blur gives the same state in both builds. I have not added a JS test because the repository has none to extend; happy to add one if you have a preferred setup.

🤖 Generated with Claude Code

With allowInput, clicking a day blurs the (alt) input first. The blur
handler committed the typed text right away — fp.clear() for an empty box,
fp.setDate() otherwise — which redraws the calendar between mousedown and
mouseup. The click then lands on a replaced element and nothing is
selected: every day had to be clicked twice.

While the pointer is down inside the calendar (or focus moves into it) the
blur is left alone; the selection or onClose commits the value. Typing and
leaving the field elsewhere commits as before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant