formaat-design / reshaped

Community repository for storing examples, reporting issues and tracking roadmap
https://reshaped.so
97 stars 3 forks source link

Autocomplete does not set custom HTML attributes for the input element #202

Closed dunkelbraun closed 7 months ago

dunkelbraun commented 7 months ago

Describe the bug When using the Autocomplete component, inputAttributes do not propagate to the input element.

To Reproduce Set inputAttributes in the Autocomplete component, for example autoComplete: "off".

<Autocomplete
  name="fruit"
  placeholder="Pick your food"
  value={value}
  onChange={handleChange}
  inputAttributes={{
    autoComplete: "off",
  }}
>
  {options.map((option) => (
    <Autocomplete.Item key={option} value={option}>
      {option}
    </Autocomplete.Item>
  ))}
</Autocomplete>

Preview: https://codesandbox.io/p/sandbox/muddy-silence-xljnfp

Expected behavior The input element should have `autocomplete="off" as attribute.

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

Additional context In the source code of Autocomplete.js, inputAttributes on TextField is set to attributes instead of textFieldProps.inputAttributes.

React.createElement(DropdownMenu.Trigger, null, (_a) => {
    var { ref } = _a, attributes = __rest(_a, ["ref"]);
    return (React.createElement(TextField, Object.assign({}, textFieldProps, { name: name, onChange: handleChange, 
        // Ignoring the type check since TS can't infer the correct html element type
        attributes: Object.assign(Object.assign({}, textFieldProps.attributes), { ref }),
        inputAttributes: Object.assign(Object.assign({}, attributes), { onFocus: (e) => {
                var _a;
                (_a = attributes.onFocus) === null || _a === void 0 ? void 0 : _a.call(attributes);
                handleFocus(e);
            }, ref: inputRef, role: "combobox" }) })));
})
blvdmitry commented 7 months ago

Thanks for reporting, I'll take a look and ship a patch today

blvdmitry commented 7 months ago

Can you check if it works for you in 2.6.4?

dunkelbraun commented 7 months ago

Works for me in 2.6.4.

Thank you.

What a quick turnaround! πŸ‘πŸ™‡