bento-design-system icon indicating copy to clipboard operation
bento-design-system copied to clipboard

Expose ref of components

Open gabro opened this issue 2 years ago • 4 comments

Apart from Box, we currently don't forward the ref prop of any of the components. This is rather arbitrary and potentially problematic in some situations.

For example, we can't use a Button directly as a trigger for Menu since it doesn't accept a ref. As another example, users of Bento can't programmatically control focus on the components in case they need to, and so on.

This is issue is potentially broad, but I propose we expose ref on every component. Where to forward ref heavily depends on the component itself: in some cases it may make sense to target the top-level wrapper of the component, in other cases we may need to target the native component we're wrapping (think of NumberInput for instance).

gabro avatar Jul 26 '22 16:07 gabro

I think we should split this in smaller chunks of work, the first piece of work would be listing the components we want to expose the ref of (I.e. a list with checkboxes in this issue) and then start working on a component-per-component basis

gabro avatar Dec 12 '22 14:12 gabro

List of components:

  • [ ] Actions
  • [ ] AreaLoader
  • [ ] Avatar
  • [ ] Banner
  • [x] Box
  • [ ] Breadcrumb
  • [ ] Button
  • [ ] ButtonLink
  • [ ] Card
  • [ ] Charts
    • [ ] BarChart
    • [ ] DonutChart
    • [ ] LineChart
  • [ ] Checkbox
  • [ ] CheckboxField
  • [ ] CheckboxGroupField
  • [ ] Chip
  • [ ] ContentBlock
  • [ ] ContentWithSidebar
  • [ ] DateField
  • [ ] Disclosure
  • [ ] DisclosureGroup
  • [ ] Divider
  • [ ] Feedback
  • [ ] Field
  • [ ] FileUploaderField
  • [ ] Form
    • [ ] FormRow
    • [ ] FormSection
  • [ ] IconButton
  • [ ] Icons
  • [ ] Illustrations
  • [ ] InlineLoader
  • [ ] Layout
    • [ ] Bleed
    • [ ] Column
    • [ ] Columns
    • [ ] Inline
    • [ ] Inset
    • [ ] Stack
    • [ ] Tiles
  • [ ] Link
  • [ ] List
    • [ ] ListItem
  • [ ] Menu
  • [ ] Modal
  • [ ] Navigation
  • [ ] NumberField
  • [ ] NumberInput
  • [ ] Popover
  • [ ] ProgressBar
  • [ ] RadioGroupField
  • [ ] ReadOnlyField
  • [ ] SearchBar
  • [ ] SelectField
  • [ ] Slider
  • [ ] SliderField
  • [ ] Stepper
  • [ ] Switch
  • [ ] Table
  • [ ] Tabs
  • [ ] TextArea
  • [ ] TextField
  • [ ] TimeField
  • [ ] Toast
  • [ ] Tooltip
  • [ ] Typography
    • [ ] Body
    • [ ] Display
    • [ ] Headline
    • [ ] Label
    • [ ] Title

federico-ercoles avatar Dec 23 '22 15:12 federico-ercoles

I had a look at what MUI does for their components that have an equivalent in Bento, and it looks to me that the default behaviour is always forwarding the ref to the root element. I haven't been able to find one with a different behaviour.

federico-ercoles avatar Dec 23 '22 16:12 federico-ercoles

There are cases in which there are multiple refs. E.g. https://mui.com/material-ui/api/input/ has an inputRef which references the inner input element

gabro avatar Dec 23 '22 16:12 gabro