Focus DateRangePicker via my app's existing Label component? #4368
-
I already have a It's minor, but it bothers me that this label situation would be different than all of the rest of my app's input elements: <Label htmlFor="firstName">First Name</Label>
<Input id="firstName" name="firstName" />
<Label htmlFor="birthYear">Born</Label>
<Select id="birthYear" name="birthYear">
<option>1987</option>
<option>1988</option>
...
</Select>
<Label htmlFor="bio">Bio</Label>
<Textarea id="bio" name="bio" />
<AppDateRangePicker id="tripDate" label="Trip Date" /> |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
One thing with this is that by using So there are two options:
You can also pass an |
Beta Was this translation helpful? Give feedback.
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 theDateRangePicker
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 anelementType
via the DateRangePicker.So there are two options:
Add a prop to your
AppLabel
component that allows passing in an element type, e.g.<AppLabel as={Label}>
. Then render theprops.as
co…