Skip to content

Commit

Permalink
fix: expose open and onOpenChange props to DatePicker component (#…
Browse files Browse the repository at this point in the history
…404)

* chore: expose `open` and `onOpenChange` props to DatePicker component

* add changeset

---------

Co-authored-by: Davis SHYAKA <87414827+davis-shyaka@users.noreply.github.com>
Co-authored-by: Hunter Johnston <64506580+huntabyte@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 18, 2024
1 parent 913d4be commit 4d1b4c1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/afraid-otters-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": minor
---

Expose `open` and `onOpenChange` props to `DatePicker.Root` component
18 changes: 17 additions & 1 deletion src/lib/bits/date-picker/components/date-picker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
type $$Props = Props;
export let open: $$Props["open"] = undefined;
export let onOpenChange: $$Props["onOpenChange"] = undefined;
export let value: $$Props["value"] = undefined;
export let onValueChange: $$Props["onValueChange"] = undefined;
export let placeholder: $$Props["placeholder"] = undefined;
Expand All @@ -31,10 +33,16 @@
export let onOutsideClick: $$Props["onOutsideClick"] = undefined;
const {
states: { value: localValue, placeholder: localPlaceholder, isInvalid: localIsInvalid },
states: {
open: localOpen,
value: localValue,
placeholder: localPlaceholder,
isInvalid: localIsInvalid,
},
updateOption,
ids,
} = setCtx({
defaultOpen: open,
defaultValue: value,
defaultPlaceholder: placeholder,
preventDeselect,
Expand Down Expand Up @@ -69,6 +77,13 @@
}
return next;
},
onOpenChange: ({ next }) => {
if (open !== next) {
onOpenChange?.(next);
open = next;
}
return next;
},
});
const idValues = derived(
Expand Down Expand Up @@ -132,6 +147,7 @@
$: value !== undefined && localValue.set(value);
$: placeholder !== undefined && localPlaceholder.set(placeholder);
$: open !== undefined && localOpen.set(open);
$: updateOption("disabled", disabled);
$: updateOption("isDateUnavailable", isDateUnavailable);
Expand Down

0 comments on commit 4d1b4c1

Please sign in to comment.