I need a TextField with a dropdown menu to offer default options, and do not want to filter the options based on the text content. All options have to be offered regardless of the actual text content.
Here is the code, ready to copy into https://suid.io/tools/playground:
import { TextField } from '@suid/material';
export default function App() {
const remotes: string[] = ['First', 'Second'];
return (
<div>
<TextField
id="ipaddr"
label="IP address"
type="text"
variant="filled"
clearOnEscape
InputProps={{
endAdornment: (
<datalist id="remotelist">
{remotes.map((r) => (
<option value={r}></option>
))}
</datalist>
),
inputProps: {
list: 'remotelist',
},
}}
/>
</div>
);
}
What's happening is that after selecting First from the dropdown, it's no more possible to select Second. Typing in arbitrary text also removes the non-matching options.
Another issue is that the clearOnEscape option does not seem to be working.
Attempted to configure the filter functions etc... to no avail. Any ideas?
The problem is you are using
adornmentprop outside its purpose. If you check the documentaiton, https://mui.com/material-ui/react-text-field/#input-adornments, it is used to add prefix or suffix pertaining to the input text and the value is rendered as an inline element.The functionality you asked is not offered out of the box, so you need to implement it yourself. If you need to keep the look and feel of MUI, you need to use built-in components.
There are few problems with @suid event handling for
TextField, only delegated events are supported, meaning you can use event handlers likeonFocusandonBlur, problem is, you have no control over the event sequence. Try enabling onBlur, you will see, the list disappears before the click event gets registered.Solid provides all lowercase event handler syntax, like
onblur, to tap into native event handling but it is not bound forTextFieldcomponent. So,onblur={handleBlur}does not work.What we are trying to achive is, when user clicks one of the ip button, we need to change the api first then hide the list. So, click event should be handled before the blur event. We need to use bubling phase.
https://developer.mozilla.org/en-US/docs/Web/API/Event/eventPhase
So, you need to resort to
refto access native event binding:Create a variable first:
Then add to the element as a prop:
But, ref does not point to actual
inputelement but the div wrapper around it, so is no use:So, library has some issues, you need find a workaround to achive:
Solution will not be hard to find, but ugly and subpar.
Alternatively you can use plain jsx elements, add classes from @suid.