Skip to content

Commit

Permalink
fix: RangeCalendar external value updates (#851)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte authored Nov 1, 2024
1 parent 1384bd6 commit 2c02d45
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/selfish-boxes-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": patch
---

fix: Range Calendar external value updates
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@
}
}
value === undefined && (value = { start: undefined, end: undefined });
const rootState = useRangeCalendarRoot({
id: box.with(() => id),
ref: box.with(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,23 @@ export class RangeCalendarRootState {
node.textContent = this.fullCalendarLabel;
});

/**
* Synchronize the start and end values with the `value` in case
* it is updated externally.
*/
$effect(() => {
const value = this.value.current;
untrack(() => {
if (value.start && value.end) {
this.startValue.current = value.start;
this.endValue.current = value.end;
} else if (value.start) {
this.startValue.current = value.start;
this.endValue.current = undefined;
}
});
});

/**
* Synchronize the placeholder value with the current start value
*/
Expand Down

0 comments on commit 2c02d45

Please sign in to comment.