Keep MUI TextField label on top when text field has no value - reactjs

So this should be simple but I don't see a clear answer.
The labels I have looks like this:
.
As you can see the bottom 2 fields have the label on top since they have a default value whereas the top on "ML Features" does not and the label moves to the middle of the TextField.
The code looks like this:
<TextField
label="ML Features" // or any other field
...
>
</TextField>
How can I keep the label always on the top?

You can set shrink to true in InputLabelProps. For more reference, see InputLabel API here.
<TextField label="ML Features" InputLabelProps={{ shrink: true }} />

you need to add focused
so that it will be in top without any value

Related

Draw line in multiline TextField of MUI (ReactJS, MUI, TextField)

I am trying to add a solid line in TextField multiline of mui, but i don't know how to do it.
The result I want:
The result I want
This is what I have
textfield.
My code looks like this:
<TextField
multiline
rows={2}
name='address'
variant='standard'
label="Địa chỉ"/>
This is possible with custom styling of the textarea, the first thing i'm thinking of is two lines which are going to be absolute positioned and the container of the textarea is going to be relative for this lines, the distance between the top and the bottom line is going to be the line height of the row.

Conditionally rendering Radio Buttons in React

I am building a React app with a hefty search functionality. Essentially, I need to conditionally render Radio buttons based on other Radio buttons input. I am using the MUI library for Radio buttons.
Here's an example of the type of functionality that I need
if (value === 'Option1') {
return <Option1Radios />
}
I know this has to do with useState, so the actual code will look nothing like the above example, but that's the best way I can explain what I'm looking for.
Currently, I have the basic set of radio options that are necessary for all searches at the top. When the user reaches the 3rd set of radio buttons, I need to take their choice in those radio buttons, and render a large selection of radio buttons based upon that 3rd selection. My current plan is to create components for each set of radio buttons that can appear, and then set it up to render those components when the proper button is checked (Option1Radio component, Option2Radio component, etc.)
Example.js
<Form.Row>
<FormControl>
<FormLabel id="demo-row-radio-buttons-group-label">Options</FormLabel>
<RadioGroup
row
aria-labelledby="demo-row-radio-buttons-group-label"
name="row-radio-buttons-group"
>
<FormControlLabel value="Option1" control={<Radio />} label="Option1" />
<FormControlLabel value="Option2" control={<Radio />} label="Option2" />
<FormControlLabel value="Option3" control={<Radio />} label="Option3" />
</RadioGroup>
</FormControl>
</Form.Row>
I have been looking for a resource on how to conditionally render Radio buttons in this way, but I've been unable to find anything. I would imagine there is some resource that shows me the proper way to set these up, so ideally if someone could link me to that (or even just a website that has implemented this type of searching that I could inspect,) that would be very helpful. If not, if someone could possibly give a code example on how to get this done I would greatly appreciate it.
My assumption on how this needs to be done:
I assume that in my main search page, I need to set the state of the search form.
I assume that I need to change the state of the search form to reflect the value of the specific radio option, so that it will render the appropriate set of options.
Thank you for the help and I'm happy to provide anything else that may help. I know this may seem like a ridiculous question, essentially asking for documentation/guide, but I have searched for a few hours now to no avail! Thank you again!
You can do conditional rendering like this:
Define the state to control the rendering:
const [contition, setCondition] = useState(false);
This code only displays <Option1Radios /> when your condition is true:
return {condition && <Option1Radios />};
Here is an article about it: https://medium.com/geekculture/stop-using-for-conditional-rendering-in-react-a0f7b96200f8. ps: I still prefer && syntax specially in TypeScript where you can ensure the variable is always a boolean.

How to show line numbers in TextField Material-UI component in multiline mode?

I'm using the TextField component in multi-line mode to edit the query text (sort of like a simple code editor), but it doesn't display line numbers. Can I somehow program to show the line numbers next to it?
<TextField
className="mt-8 mb-16 mx-4"
label="Query Text"
autoFocus
id="my_query"
name="my_query"
value={form.my_query}
onChange={handleChange}
variant="outlined"
multiline
rows={16}
fullWidth
/>
I tried to use react-simple-code-editor, but it didn't work for me due to the architecture of my web application (there is no onChange event and e object, but only onValueChange - without the e event object), and my form automatically transmits changes onChange to the form. In short, react-simple-code-editor doesn't suit me.
And it would be nice if someone could suggest how to display line numbers using the standard TextField component in multiline mode from the material-ui library.

how to show menu styles in react-select outside scroll in table?

I want to show the menus outside the table, I tried using position:"absolute" in menu:styles, but didn't work.
<Select styles={customStyles}
onChange={handleChange}
options={options}
autoFocus={true}
>
You want to read the documentation on Portaling. Currently your menu is confined to it's container element, which is why you're seeing what you're seeing.

How can I set reactdate-picker dropdown view to upper

Normal style of drop down view is at bottom after click,HOw can I set to upper place.plz Let me fix that.
Here is my nomal datepicker in reactjs.
<DatePicker
selected={this.state.startDate}
onChange={this.handleDateChange}
/>
Add prop for popperPlacement, like this:
<DatePicker
...
popperPlacement="top-start"
>
React DatePicker does that automatically if there is not enough room for it on the bottom of the page, but this way you can "force" it.
See The source for additional placement options.

Resources