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

feat: allow custom input element override for DatePicker #562

Merged
merged 2 commits into from
Nov 22, 2023

Conversation

karrui
Copy link
Collaborator

@karrui karrui commented Nov 22, 2023

allows for users to trigger the calendar without using the default input

A little convoluted to use, but allows the flexibility if needed!

Example usage

// Custom input
// !!REQUIRES `forwardRef` to be set so Popover parent knows where to anchor to.
const CustomInputButton = forwardRef<object, 'button'>((_props, ref) => {
  const { inputRef, innerRef, disclosureProps: { onOpen } } = useDatePicker()
  // !!Important to use forwarded ref so popover knows where to anchor to
  const refs = useMergeRefs(inputRef, innerRef, ref)

  return (
    <Button ref={refs} onClick={onOpen}>
      please look at source code to see how to use custom elements
    </Button>
  )
})

// Usage
<DatePicker inputElement={<CustomInputButton />} {...restOfProps} />

allows for users to trigger the calendar without using the default input
@karrui karrui merged commit eb84903 into main Nov 22, 2023
7 checks passed
@karrui karrui deleted the allow-custom-input-in-datepicker branch November 22, 2023 08:37
@karrui karrui mentioned this pull request Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant