Skip to content

Commit 8932716

Browse files
authored
fix: use minValue and maxValue to generate a defaultPlaceholder for date inputs (#1874)
1 parent ab6131d commit 8932716

File tree

15 files changed

+100
-7
lines changed

15 files changed

+100
-7
lines changed

.changeset/full-foxes-decide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"bits-ui": patch
3+
---
4+
5+
fix(Calendar, DateField, DatePicker, DateRangeField, DateRangePicker, RangeCalendar): Change default placeholder behaviour to choose the closest available value to current date, in case current date is outside of allowed range by minValue and maxValue.

docs/content/components/calendar.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ The `placeholder` prop for the `Calendar.Root` component determines what date ou
7171

7272
As the user navigates through the calendar, the `placeholder` will be updated to reflect the currently focused date in that view.
7373

74-
By default, the `placeholder` will be set to the current date, and be of type `CalendarDate`.
74+
By default, the `placeholder` will be set to the closed alowed (by `maxValue`, `minValue`) value to current date, and be of type `CalendarDate`.
7575

7676
## Managing Placeholder State
7777

docs/content/components/date-field.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Notice that in the `MyDateField` component we created, we're styling the `DateFi
103103

104104
The `placeholder` prop for the `DateField.Root` component isn't what is displayed when the field is empty, but rather what date our field should start with when the user attempts to cycle through the segments. The placeholder can also be used to set a granularity for the date field, which will determine which type of `DateValue` object is used for the `value`.
105105

106-
By default, the `placeholder` will be set to the current date, and be of type `CalendarDate`. However, if we wanted this date field to also allow for selecting a time, we could set the placeholder to a `CalendarDateTime` object.
106+
By default, the `placeholder` will be set to the closed alowed (by `maxValue`, `minValue`) value to current date, and be of type `CalendarDate`. However, if we wanted this date field to also allow for selecting a time, we could set the placeholder to a `CalendarDateTime` object.
107107

108108
```svelte
109109
<script lang="ts">

docs/src/routes/api/search.json/search.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/bits-ui/src/lib/bits/calendar/components/calendar.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
4444
const defaultPlaceholder = getDefaultDate({
4545
defaultValue: value,
46+
minValue,
47+
maxValue,
4648
});
4749
4850
function handleDefaultPlaceholder() {

packages/bits-ui/src/lib/bits/date-field/components/date-field.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
const defaultPlaceholder = getDefaultDate({
3535
granularity,
3636
defaultValue: value,
37+
minValue,
38+
maxValue,
3739
});
3840
3941
if (setPlaceholder) {

packages/bits-ui/src/lib/bits/date-picker/components/date-picker.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
const defaultPlaceholder = getDefaultDate({
5454
granularity,
5555
defaultValue: value,
56+
minValue,
57+
maxValue,
5658
});
5759
5860
function handleDefaultPlaceholder() {

packages/bits-ui/src/lib/bits/date-range-field/components/date-range-field.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@
4444
4545
function handleDefaultPlaceholder() {
4646
if (placeholder !== undefined) return;
47-
const defaultPlaceholder = getDefaultDate({ granularity, defaultValue: value?.start });
47+
const defaultPlaceholder = getDefaultDate({
48+
granularity,
49+
defaultValue: value?.start,
50+
minValue,
51+
maxValue,
52+
});
4853
placeholder = defaultPlaceholder;
4954
}
5055

packages/bits-ui/src/lib/bits/date-range-picker/components/date-range-picker.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
const defaultPlaceholder = getDefaultDate({
8686
granularity,
8787
defaultValue: value?.start,
88+
minValue,
89+
maxValue,
8890
});
8991
9092
function handleDefaultPlaceholder() {

packages/bits-ui/src/lib/bits/range-calendar/components/range-calendar.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
5151
const defaultPlaceholder = getDefaultDate({
5252
defaultValue: value?.start,
53+
minValue,
54+
maxValue,
5355
});
5456
5557
function handleDefaultPlaceholder() {

0 commit comments

Comments
 (0)