Skip to content

Focus DateRangePicker via my app's existing Label component? #4368

Answered by devongovett
dadamssg asked this question in Q&A
Discussion options

You must be logged in to vote

One thing with this is that by using <label> directly rather than <Label> from react-aria-components it won't get the HTML attributes passed to it from the DateRangePicker or other components (via context). That includes things like ids, aria attributes, event handlers, etc. Also for date picker in particular, it isn't a native <input> element under the hood, so a <label> element isn't actually the right HTML element semantically either. <Label> handles this automatically because it is sent an elementType via the DateRangePicker.

So there are two options:

  1. Add a prop to your AppLabel component that allows passing in an element type, e.g. <AppLabel as={Label}>. Then render the props.as co…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dadamssg
Comment options

Answer selected by dadamssg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants