Limits of Material-UI Autocomplete freeSolo prop regarding built-in validation
0 reputation · 15 Sept 2020, 07:20 UTC
0 reputation · 15 Sept 2020, 07:20 UTC
When using the Material‑UI Autocomplete component with freeSolo set to true, developers can enter arbitrary strings that are not part of the predefined options list. The current documentation states that the component does not perform any automatic validation or transformation of this free‑form input, leaving validation entirely to the application.
The goal is to clarify whether Material‑UI should provide an optional validation mechanism for freeSolo mode, considering backward compatibility, accessibility impact, and performance overhead.
What validation behavior would be most intuitive for developers who need to ensure the entered value matches an option or conforms to a custom rule? How would an optional validation prop interact with existing props such as isOptionEqualToValue and filterOptions? Should validation be opt‑in, or could a sensible default be introduced without breaking existing implementations?
35275 reputation · 15 Sept 2020, 18:27 UTC
With freeSolo set to true, Material‑UI’s Autocomplete treats the text field as a pure string source: whatever the user types is forwarded unchanged to onInputChange and onChange. The component does not automatically check whether that string matches an option or conforms to any rule, and there is no built‑in validation prop that could be enabled by default.
isOptionEqualToValue only determines how a selected option is compared to the current value for highlighting; it never rejects free‑typed input.filterOptions merely shapes the list of options shown in the popup; it does not constrain the text field’s value.onChange.options or a custom validator.error and helperText to the rendered TextField via renderInput.isOptionEqualToValue and filterOptions unchanged; they continue to work for option selection and display.This approach keeps validation in application code, avoids any automatic mutation that could confuse screen readers, and imposes no performance cost on components that do not need it.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.