Skip to content

Commit

Permalink
fix(date): apply keys on calendar and segment render fns
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Mar 8, 2025
1 parent 6ed644c commit 080eff3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-bees-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@formwerk/core': patch
---

fix: apply keys externally on calendar and segment components
14 changes: 11 additions & 3 deletions packages/core/src/useCalendar/useCalendarCell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export function useCalendarCell(_props: Reactivify<CalendarCellProps>) {

return withRefCapture(
{
key: toValue(props.value).toString(),
onClick: handleClick,
onPointerdown: handlePointerDown,
'aria-selected': toValue(props.selected),
Expand All @@ -51,6 +50,7 @@ export function useCalendarCell(_props: Reactivify<CalendarCellProps>) {
return {
cellProps,
label,
key: computed(() => `${toValue(props.type)}-${toValue(props.value).toString()}`),
};
}

Expand All @@ -62,8 +62,16 @@ export const CalendarCell = /*#__PURE__*/ defineComponent({
inheritAttrs: true,
props: ['value', 'selected', 'disabled', 'focused', 'label', 'type', 'monthOfYear', 'year'],
setup(props) {
const { cellProps, label } = useCalendarCell(props);
const { cellProps, label, key } = useCalendarCell(props);

return () => h('span', cellProps.value, label.value);
return () =>
h(
'span',
{
...cellProps.value,
key: key.value,
},
label.value,
);
},
});
15 changes: 12 additions & 3 deletions packages/core/src/useDateTimeField/useDateTimeSegment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export function useDateTimeSegment(_props: Reactivify<DateTimeSegmentProps>) {
});

return {
key: computed(() => `${id}-${toValue(props.type)}`),
segmentProps,
};
}
Expand All @@ -246,8 +247,16 @@ export const DateTimeSegment = /*#__PURE__*/ defineComponent<DateTimeSegmentProp
name: 'DateTimeSegment',
props: ['type', 'value', 'disabled', 'readonly'],
setup(props) {
const { segmentProps } = useDateTimeSegment(props);

return () => h('span', segmentProps.value, props.value);
const { segmentProps, key } = useDateTimeSegment(props);

return () =>
h(
'span',
{
...segmentProps.value,
key: key.value,
},
props.value,
);
},
});

0 comments on commit 080eff3

Please sign in to comment.