Skip to content

feat(datepickers): add optional hasClearButton prop to datepickers#1088

Open
hoorayimhelping wants to merge 1 commit into
mainfrom
bucky-datepicker-close
Open

feat(datepickers): add optional hasClearButton prop to datepickers#1088
hoorayimhelping wants to merge 1 commit into
mainfrom
bucky-datepicker-close

Conversation

@hoorayimhelping

@hoorayimhelping hoorayimhelping commented Jun 18, 2026

Copy link
Copy Markdown
Member
  • Adds clear buttons to the three date pickers, which clears out the dates when clicked
Screenshot 2026-06-18 at 4 21 15 PM
Screenshot 2026-06-18 at 4 21 24 PM
Screenshot 2026-06-18 at 4 21 33 PM
Screen.Recording.2026-06-18.at.4.24.23.PM.mov

Closes https://linear.app/clickhouse/issue/CUI-178/datepickers-add-a-prop-controlled-clear-button


Note

Low Risk
Opt-in UI with local state only; main integration caveat is that clear does not invoke onSelectDate / onSelectDateRange, so parents must handle empty state themselves if needed.

Overview
Adds an opt-in hasClearButton prop on DatePicker, DateRangePicker, and DateTimeRangePicker that shows a cross control on the right of the trigger input. Clearing resets internal selection (and partial year/month on the single date picker) without opening the popover/dropdown; range pickers also stop pointerdown on the clear control so the dropdown trigger does not toggle.

Shared input UI in Common.tsx introduces a styled ClearButton (span with role="button", not IconButton) to avoid invalid button-in-button nesting inside popover/dropdown triggers. Layout tweaks include optional $minWidth on the highlighted wrapper and max-content width when the clear control is shown on range inputs.

Stories, tests, and a minor changeset are included. Note: the changeset text refers to hasCloseButton, while the public API is hasClearButton.

Reviewed by Cursor Bugbot for commit 383bd87. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot

changeset-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 383bd87

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clickhouse/click-ui Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 40fefbc. Configure here.

Comment thread src/components/DatePicker/DatePicker.tsx
Comment thread src/components/DatePicker/Common.tsx
@hoorayimhelping hoorayimhelping force-pushed the bucky-datepicker-close branch from 40fefbc to 383bd87 Compare June 18, 2026 21:11
@workflow-authentication-public

Copy link
Copy Markdown
Contributor

Storybook Preview Deployed

✅ Preview URL: https://click-ff7ye9oy2-clickhouse.vercel.app

Built from commit: 62c4b82831a51f783ec154d7a4286ee2fee169fc

@DreaminDani

Copy link
Copy Markdown
Contributor

@crisalbu are you cool with the input changing size so much? @hoorayimhelping I assume a consumer of this input can avoid the changing width by just setting a reasonable min-width, yeah?

@crisalbu

Copy link
Copy Markdown
Collaborator

If we have a date time range picker, I feel that we should have a min width for it by default that takes into consideration how much space we need to display those values.
It's always a bit jarring when a component dynamically changes size- Wdyt @hoorayimhelping @DreaminDani ?

},
},
component: DatePicker,
render: (args: Args) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

side note: args should be spread onto the component in default story, right now you can't use the knobs to play around with it

resetPartialState();
setSelectedDate(undefined);
}, [resetPartialState]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this clears internal state but does nothing for consumer
we need to call onSelectDate with undefined

same for other datepickers

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

just something I noticed
we don't specify year in datetime range picker, so I can't tell when selected year is differnet from current
if we start showing it (which we should) this adds to the @crisalbu's concern about jumpy width, since the max possible width would be even bigger

Image

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good thing you mentioned that @ariser! Let's account for the year as well when we pick the width.

By default, we don't show the year if it's the current year, but we do display it when it's past years.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Well we don't, in current implementation :) we should fix that, but perhaps in a separate PR

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That would be great if we could :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it should be a separate PR. I just implemented this behavior in a date formatter in CP.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

100%, not this PR's concern

name="cross"
size="sm"
/>
</ClearButton>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why isn't this an IconButton?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@ariser the hover styling on IconButton overflowed the input and couldn't be changed

@hoorayimhelping

Copy link
Copy Markdown
Member Author

If we have a date time range picker, I feel that we should have a min width for it by default that takes into consideration how much space we need to display those values.

@crisalbu @DreaminDani here's the issue with that: If we dynamically decide to show the year in a range picker that has two dates, we have to size it to the maximum possible size, because we won't know what year the selected date will be. The problem is, it's already huge without years:

@crisalbu

crisalbu commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

If we have a date time range picker, I feel that we should have a min width for it by default that takes into consideration how much space we need to display those values.

@crisalbu @DreaminDani here's the issue with that: If we dynamically decide to show the year in a range picker that has two dates, we have to size it to the maximum possible size, because we won't know what year the selected date will be. The problem is, it's already huge without years:

How bout we set the min-with to be optimized for dates without years, and automatically resize when it has years?


You know what would help with the width? using 24h times, instead of a.m. / p.m. 😉

11:00 a.m.
11:00
12:00 a.m.
0:00
2:00 p.m
14:00

Out of scope for this PR, but maybe worth rediscussing during our next UX-dev call?

@DreaminDani

Copy link
Copy Markdown
Contributor

How bout we set the min-with to be optimized for dates without years, and automatically resize when it has years?

I like this idea :)

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.

4 participants