Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: datepicker custom id #2040

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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