how to remove border in textfield fieldset in material ui - css

I need to remove the border. I used some css from stack overflow but the issue is not fixed yet . If any one please help me to fixed this issue .I shall be very thank full.
what css I write to remove the border.
<TextField
variant="outlined"
margin="normal"
required
fullWidth
id="phoneNumber"
disableUnderline={false}
// label="Phone Number"
name="phoneNumber"
autoComplete="phoneNumber"
autoFocus
onChange={handlePhoneNumberChange}
className={classes.textField}
placeholder="Phone Number"
InputProps={{
startAdornment: (
<InputAdornment position="start">
<AccountCircle />
</InputAdornment>
),
}}
/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.1.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.1.1/umd/react-dom.production.min.js"></script>

I was looking for a borderless text-field and this is working for me...
<TextField
variant="standard" // <== changed this
margin="normal"
required
fullWidth
id="phoneNumber"
name="phoneNumber"
autoComplete="phoneNumber"
autoFocus
onChange={handlePhoneNumberChange}
placeholder="Phone Number"
InputProps={{
startAdornment: <AccountCircle />, // <== adjusted this
disableUnderline: true, // <== added this
}}
/>
These 2 props seem to be the key...
variant="standard"
InputProps={{
disableUnderline: true,
}}

InputProps can be passed to the style the variants of the inputs. For outlined input there a class named .MuiOutlinedInput-notchedOutline which sets the border in this question's case. To modify this class, pass the styles to the notchedOutline prop in InputProps.
const useStyles = makeStyles(() => ({
noBorder: {
border: "none",
},
}));
const TextInput = props => {
const { onChange, type} = props;
const classes = useStyles();
return (
<TextField
variant="outlined"
margin="normal"
required
fullWidth
id="phoneNumber"
disableUnderline={false}
// label="Phone Number"
name="phoneNumber"
autoComplete="phoneNumber"
autoFocus
classes={{notchedOutline:classes.input}}
// onChange={handlePhoneNumberChange}
className={classes.textField}
placeholder="Phone Number"
InputProps={{
startAdornment: (
<InputAdornment position="start">
<AccountCircle />
</InputAdornment>
),
classes:{notchedOutline:classes.noBorder}
}}
/>
);
};
Here is the working sandbox link: https://codesandbox.io/s/material-demo-forked-nhlde

to remove border in TextField fieldset in MUI 5,
simply add following.
sx={{
"& fieldset": { border: 'none' },
}}

I tried all the answers here.
Doesn't work
I found this InputBase
It works very nicely.
This is exactly what you should use.
They have provided the sandbox too
Sandbox InputBase

In your textField style add outline: 'none'

As at 2022, if your using MUI >= version 5, you can use some solutions here, and currently there's no where in the doc on how do this in Textfield.
Another nice component MUI provides is the Input, and luckily for us it accepts almost all props passed to Textfield, that's where you can do disableUnderline={false} and it will work as expected.
<Input
disableUnderline={true}
variant="standard"
autoFocus
onChange={yourChangeHandler}
value={value}
placeholder="Title"
fullWidth
/>

Finally, the following css works (2022)
'& .MuiInput-root': {
'&:before, :after, :hover:not(.Mui-disabled):before': {
borderBottom: 0,
},
},

For Outlined TextField
If you want to remove outlines from the outlined text field. Then add this in your TextField
sx={{border: 'none',"& fieldset": { border: 'none' },}}
Here is your code...
<TextField
variant="outlined"
sx={{border: 'none', "& fieldset": { border: 'none' },}}
margin="normal"
required
fullWidth
id="phoneNumber"
disableUnderline={false}
// label="Phone Number"
name="phoneNumber"
autoComplete="phoneNumber"
autoFocus
onChange={handlePhoneNumberChange}
className={classes.textField}
placeholder="Phone Number"
InputProps={{
startAdornment: (
<InputAdornment position="start">
<AccountCircle />
</InputAdornment>
),
}}
/>
For Standard TextField
If you want to remove underline from the standard text field. Then add this in your TextField
InputProps={{ disableUnderline: true }}
Here is code
<TextField
fullWidth
placeholder="Search..."
InputProps={{ disableUnderline: true }}
/>

Added sx prop with below attributes in TextField and it worked fine for me
<TextField
sx={{
input: {
border: "none",
},
"::placeholder": { color: "white" },
}}
/>

The documentation doesn't offer any good way to do this
So you can select the Mui selector for that element and modify it directly
This worked for me.
You can override the css
<TextField
id="outlined-basic"
label="Outlined"
variant="outlined"
sx={{ "& .MuiOutlinedInput-notchedOutline": { border: "none" } }}
/>
<TextField
id="filled-basic"
label="Filled"
variant="filled"
sx={{
"& .MuiFilledInput-underline:before": {
borderBottom: "none",
},
"& .MuiFilledInput-underline:after": {
borderBottom: "none",
},
"& .MuiFilledInput-underline:hover:not(.Mui-disabled):before": {
borderBottom: "none",
},
}}
/>
Please check it in codesandbox

Try to override style
See example below

disableUnderline
If true, the input will not have an underline.
<Input
variant="standard"
disableUnderline={true}
required
color="info"
fullWidth
margin="dense"
focused
/>
API

Just add
".MuiOutlinedInput-notchedOutline": { border: "none" },
to the sx prop.
This works both for MUI Select and Textfield

If you want to remove the border for all MuiOutlinedInput components, add this to your theme's components object:
export const theme = createTheme({
// ...
components: {
// ...
MuiOutlinedInput: {
styleOverrides: {
notchedOutline: {
border: 'none',
},
},
},
},
})

Related

How to align startIcon material ui icon at the center?

I'm attempting to keep the icon button center aligned, but something isn't working right. Adding left: "0.5rem" to sx prop is pushing the button icon further. I'm trying not to use makeStyles to override the position. Any tip/direction would be helpful :)
Sandbox link
You can try using style:
<Stack direction="row" style={{display:"flex", justifyContent:"center", alignItems:"center"}}>
<Tooltip title="Delete">
<Button sx={{ minWidth: 0 }} startIcon={<DeleteIcon />} />
</Tooltip>
<Divider orientation="vertical" flexItem />
<Tooltip title="Send">
<Button sx={{ minWidth: 0 }} startIcon={<SendIcon />} />
</Tooltip>
<Tooltip title="Headset">
<Button sx={{ minWidth: 0 }} startIcon={<HeadsetMicOutlined />} />
</Tooltip>
<Divider orientation="vertical" flexItem />
</Stack>
In case you want to set it in you theme here is how you can do it so you don't have to do it in every Button component.
export const theme = createTheme({
...
components: {
MuiButton: {
styleOverrides: {
startIcon: {
margin: '0'
},
},
}
},
});

How do I change borderColor in native base Select Component?

I'm trying to change the borderColor on this Select Component from Native base.
Here is an image of the default color and the focused color:
The border is black by default. I already tried with borderColor="" and none/unset but it isn't changing the color.
How can I change the default and active border color?
The code is here..
useState,
} from 'react';
import {
Box,
Select,
CheckIcon,
} from 'native-base';
function Dropdown({
options = [],
placeholder,
backgroundColor,
className,
onChange = () => {},
}) {
const [value, setValue] = useState('');
return (
<Box>
<Box width="3/4" maxWidth="300">
<Select
className={className}
onChange={onChange}
minWidth="200"
selectedValue={value}
accessibilityLabel="Choose Service"
placeholder={placeholder}
backgroundColor={backgroundColor}
_selectedItem={{
bg: 'teal.600',
endIcon: <CheckIcon size="5" />,
}}
_focus={{
bg: 'white',
}}
marginTop={1}
onValueChange={(itemValue) => setValue(itemValue)}
>
{options.map((option) => (
<Select.Item
label={option.label}
value={option.value}
key={option.value}
style={{ display: 'flex', flexDirection: 'column', padding: 5 }}
/>
))}
</Select>
</Box>
</Box>
);
}```
You can use borderColor to specify border color and borderWidth to specify border width. To specify border color for focused inside _focus.
const Example = () => {
let [service, setService] = React.useState('');
return (
<Center>
<Box w="3/4" maxW="300">
<Select
_focus={{ borderColor: 'yellow.500' }}
borderColor="red.500"
selectedValue={service}
minWidth="200"
accessibilityLabel="Choose Service"
placeholder="Choose Service"
_selectedItem={{
bg: 'teal.600',
endIcon: <CheckIcon size="5" />,
}}
mt={1}
onValueChange={(itemValue) => setService(itemValue)}
>
<Select.Item label="UX Research" value="ux" />
<Select.Item label="Web Development" value="web" />
<Select.Item label="Cross Platform Development" value="cross" />
<Select.Item label="UI Designing" value="ui" />
<Select.Item label="Backend Development" value="backend" />
</Select>
</Box>
</Center>
);
};

How to change Material-UI TextField InputAdornment background color?

First 10% one background color ,another 90% another background color.
<TextField
className={classes.root}
type="text"
placeholder="username"
variant="outlined"
style={{borderRadius:'50',
backgroundColor: "white"
}}
InputProps={{
startAdornment: (
<InputAdornment position="start">
<PersonIcon />
</InputAdornment>
)
}}
/>
I attach demo textfield in below
This is how you override the InputAdornment to achieve the same effect in your screenshot. Note that the input next to the InputAdornment has its box-sizing set to content-box, so it's not as simple as setting the height to 100% in the adornment. I had to copy the padding code here to make sure the height of the adornment is the same as the height of the OutlinedInput:
<TextField
placeholder="With normal TextField"
sx={{
"& .MuiOutlinedInput-root": {
paddingLeft: 0
}
}}
InputProps={{
startAdornment: (
<InputAdornment
sx={{
padding: "27.5px 14px",
backgroundColor: (theme) => theme.palette.divider,
borderTopLeftRadius: (theme) =>
theme.shape.borderRadius + "px",
borderBottomLeftRadius: (theme) =>
theme.shape.borderRadius + "px"
}}
position="start"
>
kg
</InputAdornment>
)
}}
Live Demo
V5
V4
You can do this in simple way .Try this one
InputProps={{
startAdornment: (
<div style={{display:'flex',flexDirection:'column',justifyContent:'center',alignContent:'center', backgroundColor:'#E1E8EB',height:55,width:50,marginLeft:-13,border:'0px solid green',marginRight:5}}>
<InputAdornment position="start">
<VpnKeyIcon style={{marginLeft:10}} />
</InputAdornment>
</div>
)
}}

React Material UI Tabs adding indicator color via hex?

I got this Material UI component
<Tabs
textColor="primary"
indicatorColor="primary"
>
<Tab label="All Issues"/>
</Tabs>
According to the doc indicatorColor and textColor can only be set to 'primary' or 'secondary', it's an enumeration. I want to be able to set those colors to a custom hex value. I tried just hard coding in like 'textcolor="#ffffff"', but it didn't work. Any advice?
You can use indicator and label for chaning the css for the tabs.
jss changes
const styles = theme => ({
label: {
color: '#FFF000'
},
indicator: {
backgroundColor: '#FFF'
}
});
Tabs like this
<Tabs indicatorColor="primary" classes={{ indicator: classes.indicator }} value={value} onChange={this.handleChange}>
<Tab classes={{ label: classes.label }} label="Item One" />
<Tab classes={{ label: classes.label }} label="Item Two" />
<Tab classes={{ label: classes.label }} label="Item Three" />
</Tabs>
Here in this above code the tab label will render yellow and indicator as white
check out the working example here: https://codesandbox.io/s/8111zjxm0l
Hope this will help.
Just follow these step mui v5.8.4 work for me
<Tabs
orientation="vertical"
variant="scrollable"
value={valueTab}
onChange={handleChangeTabs}
aria-label="Vertical tabs example"
sx={{
"& button:hover": { background: "your color on hover" },
"& button.Mui-selected": { background: "your color on slected",color:"your text color on selected " },
}}
textColor="secondary"
TabIndicatorProps={{
style: {
backgroundColor: "#5B4A42",
},
}}
>
Image

How can I get input radio elements to horizontally align in react [material-ui]?

The radio group is always vertical listed in material-ui. Is there a way to horizontally align them? e.g. all radio button in one horizontal line.
Simply use the row property:
<RadioGroup row><Radio /><Radio /></RadioGroup>
RadioGroup inherits from FormGroup so the properties of the FormGroup component are also available.
Another example, with labels:
<RadioGroup aria-label="anonymous" name="anonymous" value={false} row>
<FormControlLabel value="true" control={<Radio />} label="Yes" />
<FormControlLabel value="false" control={<Radio />} label="No" />
</RadioGroup>
To render the radio buttons in a row:
<RadioButtonGroup style={{ display: 'flex' }}>
To reset sizing according to content:
<RadioButton style={{ width: 'auto' }} />
Simply add the prop row={true} on the RadioGroup control.
<RadioGroup
aria-label="Location"
name="location"
className={classes.group}
value={location}
onChange={handleChange}
row={true}
>
<FormControlLabel value="company" control={<Radio />} label="Company" />
<FormControlLabel value="home" control={<Radio />} label="Home" />
<FormControlLabel value="other" control={<Radio />} label="Other" />
</RadioGroup>
For those who are still struggling, use this style:
const styles = theme => ({
group: {
width: 'auto',
height: 'auto',
display: 'flex',
flexWrap: 'nowrap',
flexDirection: 'row',
}
});
class MyComponent extends React.Component {
render() {
const { classes } = this.props;
<RadioGroup className={classes.group} ...>
}
};
export default withStyles(styles)(MyComponent);
You just need to mention row in <RadioGroup>.
You can write your code like this:
<FormControl component="fieldset">
<FormLabel >Lable</FormLabel>
<RadioGroup aria-label="overall_sal" name="Overall SAL" value={value} onChange={handleChange} row>
<FormControlLabel value="low" control={<Radio />} label="Low" />
</RadioGroup>
</FormControl>
I cant comment yet, but to add to what #lambdakris said:
You may also need to add flexDirection: 'row'. The easiest way to make these changes instead of using the inline styles is to add your css to the styles object and class that material-ui already uses.
const styled = theme => ({
formControl: {
margin: theme.spacing.unit * 3,
width: "100%", //parent of radio group
},
group: {
flexDirection: 'row',
justifyContent: 'space-around',
}
});
...........
<RadioButtonGroup className={classes.group}>

Resources