reach / reach-ui

The Accessible Foundation for React Apps and Design Systems
https://reacttraining.com/reach-ui/
MIT License
5.98k stars 560 forks source link

Incorrect prop types on ListboxButton #929

Open afk-mario opened 2 years ago

afk-mario commented 2 years ago

🐛 Bug report

Current Behavior

Getting the following error:

**Warning: Failed prop type: Invalid prop `arrow` supplied to `ListboxButton`, expected one of type [boolean].**

And this is how I'm using the Listbox

function Listbox({ options, className, ...rest }) {
  const customClassName = classnames(`${classNamePrefix}`, className);

  return (
    <ListboxInput className={customClassName} {...rest}>
      <ListboxButton
        className={`${classNamePrefix}-button`}
        arrow={() => <CgChevronDown />}
      />
      <ListboxPopover className={`${classNamePrefix}-popover`}>
        <ListboxList className={`${classNamePrefix}-list`}>
          {options.map(({ value, label }) => {
            return (
              <ListboxOption
                key={value}
                value={value}
                className={`${classNamePrefix}-option`}
              >
                {label}
              </ListboxOption>
            );
          })}
        </ListboxList>
      </ListboxPopover>
    </ListboxInput>
  );
}

Expected behavior

Listbox Button accepts a boolean or node

Reproducible example

https://codesandbox.io/s/hidden-rain-mbovdk?file=%2Fsrc%2Findex.js

jonrutter commented 2 years ago

Hi @afk-mario! I think this is an issue with your code. The component expects arrow to be a boolean or node, and you are passing it a function. It should work correctly if you pass it the icon directly:

<ListboxButton
  className={`${classNamePrefix}-button`}
  arrow={<CgChevronDown />}
/>

Here's a sandbox of a working example: https://codesandbox.io/s/charming-brahmagupta-emibiv?file=/src/index.js

afk-mario commented 2 years ago

The component expects arrow to be a boolean or node,

You are right! I missed it I think I did because the error is

Warning: Failed prop type: Invalid prop `arrow` supplied to `ListboxButton`, expected one of type [boolean].

instead of

[Warning: Failed prop type: Invalid prop `arrow` supplied to `ListboxButton`, expected one of type [boolean, node].