Skip to content

Commit

Permalink
fix: datepicker custom id (#2040)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasaarcoverde authored Nov 7, 2024
2 parents 65db519 + dc00550 commit 7e731c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
5 changes: 3 additions & 2 deletions packages/shoreline/src/components/date-picker/date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ export function DatePicker<T extends DateValue>(props: DatePickerProps<T>) {
const state = useDatePickerState(domProps)
const ref = useRef(null)
const anchorRef = useRef<HTMLDivElement>(null)
const { groupProps, labelProps, fieldProps, buttonProps, calendarProps } =
useDatePicker(domProps, state, ref)

const store = useFieldContext()
const { id: contextId, error: contextError } = useStore(store, (s) => s)

const id = defaultId || contextId
const error = defaultError || contextError

const { groupProps, labelProps, fieldProps, buttonProps, calendarProps } =
useDatePicker({ ...domProps, id }, state, ref)

return (
<PopoverProvider
open={state.isOpen}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@ export function DateRangePicker<T extends DateValue>(
const state = useDateRangePickerState(domProps)
const ref = useRef(null)
const anchorRef = useRef<HTMLDivElement>(null)

const store = useFieldContext()
const { id: contextId, error: contextError } = useStore(store, (s) => s)

const id = defaultId || contextId
const error = defaultError || contextError

const {
groupProps,
labelProps,
startFieldProps,
endFieldProps,
buttonProps,
calendarProps,
} = useDateRangePicker(domProps, state, ref)

const store = useFieldContext()
const { id: contextId, error: contextError } = useStore(store, (s) => s)

const id = defaultId || contextId
const error = defaultError || contextError
} = useDateRangePicker({ ...domProps, id }, state, ref)

return (
<PopoverProvider
Expand All @@ -52,7 +53,6 @@ export function DateRangePicker<T extends DateValue>(
<div ref={anchorRef} data-sl-date-range-picker>
<div {...labelProps} />
<div
id={id}
data-sl-date-range-picker-input
{...groupProps}
ref={ref}
Expand Down

0 comments on commit 7e731c4

Please sign in to comment.