Skip to content

Commit 48e76fc

Browse files
authored
feat: readonly startValue prop (#212)
1 parent cfd703c commit 48e76fc

File tree

7 files changed

+85
-6
lines changed

7 files changed

+85
-6
lines changed

.changeset/forty-wasps-double.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"bits-ui": patch
3+
---
4+
5+
feat: readonly startValue prop

src/content/api-reference/date-range-picker.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,14 @@ const root: APISchema<DateRangePicker.Props> = {
204204
description: "Override the focus when the popover is closed."
205205
},
206206
portal: { ...portalProp("popover") },
207-
207+
startValue: {
208+
type: {
209+
type: C.UNION,
210+
definition: union("DateValue", "undefined")
211+
},
212+
description:
213+
"The `start` value of the date range, which can exist prior to the true `value` being set, which is only set once a `start` and `end` value are selected. You can `bind:startValue` to a value to receive updates, but modifying this value outside the component will have no effect. To programmatically control the `start` value, use `bind:value` and update the `start` property of the `DateRange` object. This is provided as a convenience for use cases where you want to display the selected `start` value outside the component before the `value` is set."
214+
},
208215
asChild
209216
},
210217
slotProps: {

src/content/api-reference/range-calendar.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
attrsSlotProp,
66
weekdaysSlotProp,
77
enums,
8-
monthsSlotProp
8+
monthsSlotProp,
9+
union
910
} from "@/content/api-reference/helpers.js";
1011
import type * as RangeCalendar from "$lib/bits/range-calendar/_types.js";
1112
import { builderAndAttrsSlotProps } from "./helpers";
@@ -122,6 +123,30 @@ export const root: APISchema<RangeCalendar.Props> = {
122123
"If `true`, the calendar will focus the selected day, today, or the first day of the month in that order depending on what is visible when the calendar is mounted.",
123124
default: C.FALSE
124125
},
126+
/**
127+
* The `start` value of the date range, which can exist prior
128+
* to the `value` being set. The `value` is only set once a `start`
129+
* and `end` value are selected.
130+
*
131+
* You can `bind:startValue` to a value to receive updates outside
132+
* this component when the user selects a `start` value.
133+
*
134+
* Modifying this value outside the component will have no effect.
135+
* To programmatically control the `start` value, use `bind:value`
136+
* and update the `start` property of the `DateRange` object.
137+
*
138+
* This is provided as a convenience for use cases where you want
139+
* to display the selected `start` value outside the component before
140+
* the `value` is set.
141+
*/
142+
startValue: {
143+
type: {
144+
type: C.UNION,
145+
definition: union("DateValue", "undefined")
146+
},
147+
description:
148+
"The `start` value of the date range, which can exist prior to the true `value` being set, which is only set once a `start` and `end` value are selected. You can `bind:startValue` to a value to receive updates, but modifying this value outside the component will have no effect. To programmatically control the `start` value, use `bind:value` and update the `start` property of the `DateRange` object. This is provided as a convenience for use cases where you want to display the selected `start` value outside the component before the `value` is set."
149+
},
125150
asChild
126151
},
127152
slotProps: {

src/lib/bits/date-range-picker/_types.ts

+18
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ type Props = Expand<
6565
* This is used to apply the appropriate `aria-describedby` attribute to the input.
6666
*/
6767
descriptionId?: string;
68+
69+
/**
70+
* The `start` value of the date range, which can exist prior
71+
* to the `value` being set. The `value` is only set once a `start`
72+
* and `end` value are selected.
73+
*
74+
* You can `bind:startValue` to a value to receive updates outside
75+
* this component when the user selects a `start` value.
76+
*
77+
* Modifying this value outside the component will have no effect.
78+
* To programmatically control the `start` value, use `bind:value`
79+
* and update the `start` property of the `DateRange` object.
80+
*
81+
* This is provided as a convenience for use cases where you want
82+
* to display the selected `start` value outside the component before
83+
* the `value` is set.
84+
*/
85+
startValue?: DateValue | undefined;
6886
} & AsChild
6987
>;
7088

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727
export let fixedWeeks: $$Props["fixedWeeks"] = undefined;
2828
export let calendarLabel: $$Props["calendarLabel"] = undefined;
2929
export let weekdayFormat: $$Props["weekdayFormat"] = undefined;
30+
export let startValue: $$Props["startValue"] = undefined;
3031
3132
const {
3233
states: {
3334
value: localValue,
3435
placeholder: localPlaceholder,
3536
isInvalid: localIsInvalid,
36-
startValue,
37+
startValue: localStartValue,
3738
endValue
3839
},
3940
updateOption,
@@ -182,6 +183,7 @@
182183
ids.rangeField.field.description.set(descriptionId);
183184
}
184185
186+
$: startValue = $localStartValue;
185187
$: value !== undefined && localValue.set(value);
186188
$: placeholder !== undefined && localPlaceholder.set(placeholder);
187189
@@ -205,7 +207,7 @@
205207
$: slotProps = {
206208
isInvalid: $localIsInvalid,
207209
ids: $idValues,
208-
startValue: $startValue,
210+
startValue: $localStartValue,
209211
endValue: $endValue
210212
};
211213
</script>

src/lib/bits/range-calendar/_types.ts

+19
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type Props = Expand<
4848
* A callback function called when the placeholder changes.
4949
*/
5050
onPlaceholderChange?: OnChangeFn<DateValue>;
51+
5152
/**
5253
* If `true`, the calendar will focus the selected day,
5354
* today, or the first day of the month in that order depending
@@ -56,6 +57,24 @@ type Props = Expand<
5657
* @default false
5758
*/
5859
initialFocus?: boolean;
60+
61+
/**
62+
* The `start` value of the date range, which can exist prior
63+
* to the `value` being set. The `value` is only set once a `start`
64+
* and `end` value are selected.
65+
*
66+
* You can `bind:startValue` to a value to receive updates outside
67+
* this component when the user selects a `start` value.
68+
*
69+
* Modifying this value outside the component will have no effect.
70+
* To programmatically control the `start` value, use `bind:value`
71+
* and update the `start` property of the `DateRange` object.
72+
*
73+
* This is provided as a convenience for use cases where you want
74+
* to display the selected `start` value outside the component before
75+
* the `value` is set.
76+
*/
77+
startValue?: DateValue | undefined;
5978
} & AsChild
6079
>;
6180

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
export let id: $$Props["id"] = undefined;
3030
export let weekdayFormat: $$Props["weekdayFormat"] = undefined;
3131
export let initialFocus: $$Props["initialFocus"] = false;
32+
export let startValue: $$Props["startValue"] = undefined;
3233
3334
let el: HTMLElement | undefined = undefined;
3435
@@ -44,7 +45,7 @@
4445
placeholder: localPlaceholder,
4546
months,
4647
weekdays,
47-
startValue,
48+
startValue: localStartValue,
4849
endValue
4950
},
5051
updateOption,
@@ -85,6 +86,8 @@
8586
ids.calendar.set(id);
8687
}
8788
89+
$: startValue = $localStartValue;
90+
8891
$: value !== undefined && localValue.set(value);
8992
$: placeholder !== undefined && localPlaceholder.set(placeholder);
9093
@@ -112,7 +115,7 @@
112115
builder,
113116
months: $months,
114117
weekdays: $weekdays,
115-
startValue: $startValue,
118+
startValue: $localStartValue,
116119
endValue: $endValue
117120
};
118121
</script>

0 commit comments

Comments
 (0)