Trying to get the submenu items in antd scrollable, with the below code
Codesandbox Link: https://codesandbox.io/s/dazzling-antonelli-t4g3nu?file=/index.js
import ReactDOM from "react-dom";
import "antd/dist/antd.css";
import "./index.css";
import { Menu, Icon } from "antd";
const { SubMenu } = Menu;
function handleClick(e) {
console.log("click", e);
}
const options = [
{ key: "1", value: "option1" },
{ key: "2", value: "option12" },
{ key: "3", value: "option13" },
{ key: "4", value: "option14" },
{ key: "5", value: "option15" },
{ key: "6", value: "option16" },
{ key: "7", value: "option17" },
{ key: "8", value: "option18" },
{ key: "9", value: "option19" },
{ key: "10", value: "option134" },
{ key: "11", value: "option132" },
{ key: "12", value: "option142" },
{ key: "13", value: "option123" }
];
ReactDOM.render(
<Menu onClick={handleClick} style={{ width: 256 }} mode="vertical">
<SubMenu
key="sub4"
title={
<span>
<Icon type="setting" />
<span>Navigation Three</span>
</span>
}
>
<div style={{ height: "100px", overflow: "scroll" }}>
{options?.map((data) => {
return <li style={{ lineHeight: "20px" }}> {data?.value} </li>;
})}
</div>
</SubMenu>
</Menu>,
document.getElementById("container")
);
the items displayed in submenu is not scrollable even though the scroll icon is present, need some help in fixing it.
Thanks.
You have to return Item in the Submenu.
https://codesandbox.io/s/interesting-sky-wmytdr?file=/index.js:805-1075
<SubMenu
key="sub4"
title={
<span>
<Icon type="setting" />
<span>Navigation Three</span>
</span>
}
>
{options?.map((data) => {
return <Menu.Item> {data?.value} </Menu.Item>;
})}
</SubMenu>
To have scroll, you have to target the ant-submenu
.ant-menu-submenu-popup {
max-height: 100px ;
overflow: auto ;
}
There is a :pseudo-element overlaying the popup which prevents the scrolling.
Add this .ant-menu-submenu-popup::before:
pointer-events: none;
Related
I'm trying to change the width, height and color of table pagination on Material-ui V5.0 with React, but it does not accept classes. As the pagination uses .MuiToolbar-root, if I make changes with a .css file, it brakes my MuiToolbar at the top of the App page. How should I apply the changes needed without braking the Appbar at the top? Also, I will need to change the padding of .MuiTableCell-root as well. I'm sending my code bellow. Please all helps will be very appreciated.
// Component SupplierTable
import React, {useState} from 'react'
import './SupplierTable.css';
import SupplierForm from './SupplierForm';
import PageHeader from '../components/PageHeader';
import FactoryIcon from '#mui/icons-material/Factory';
import * as supplierService from '../services/EmployeeService';
import Controls from "../components/controls/Controls";
import { InputAdornment } from '#mui/material';
import SearchIcon from '#mui/icons-material/Search';
import AddIcon from '#mui/icons-material/Add';
import Box from '#mui/material/Box';
import Paper from '#mui/material/Paper';
import useTable from "../components/useTable";
import { makeStyles } from '#mui/styles';
import ModeEditOutlineIcon from '#mui/icons-material/ModeEditOutline';
import { TableRow, TableBody, TableCell } from '#mui/material';
import CloseIcon from '#mui/icons-material/Close';
import Popup from '../components/Poup';
import Notification from '../components/Notifications';
import ConfirmDialog from '../components/ConfirmDialog';
import Grid from '#mui/material/Grid';
const useStyles = makeStyles(theme => ({
overrides: {
'&.MuiTablePagination-root':{
width: '960px',
height: '35px',
backgroundColor: '#a9aeb3',
color: 'rgb(41, 39, 39)',
fontFamily: 'Arial, Helvetica, sansSerif',
fontWeight: '700',
}
},
pageContent: {
margin: theme.spacing(1),
padding: theme.spacing(3)
},
searchInput: {
width: '50%'
},
newButton: {
position: 'absolute',
right: '0px'
},
}));
const headCells = [
{ id: 'fullName', label: 'Employee Name' },
{ id: 'email', label: 'Email Address (Personal)' },
{ id: 'mobile', label: 'Mobile Number' },
{ id: 'department', label: 'Department' },
{ id: 'actions', label: 'Actions', disableSorting: true }
]
export default function Supplyer() {
const classes = useStyles();
const [recordForEdit, setRecordForEdit] = useState(null)
const [records, setRecords] = useState(supplierService.getAllSuppliers())
const [filterFn, setFilterFn] = useState({ fn: items => { return items; } })
const [openPopup, setOpenPopup] = useState(false)
const [notify, setNotify] = useState({ isOpen: false, message: '', type: '' })
const [confirmDialog, setConfirmDialog] = useState({ isOpen: false, title: '', subTitle: '' })
const {
TblContainer,
TblHead,
TblPagination,
recordsAfterPagingAndSorting
} = useTable(records, headCells, filterFn);
const handleSearch = e => {
let target = e.target;
setFilterFn({
fn: items => {
if (target.value == "")
return items;
else
return items.filter(x => x.fullName.toLowerCase().includes(target.value))
}
})
}
const addOrEdit = (employee, resetForm) => {
if (employee.id == 0)
supplierService.insertEmployee(employee)
else
supplierService.updateEmployee(employee)
resetForm()
setRecordForEdit(null)
setOpenPopup(false)
setRecords(supplierService.getAllEmployees())
setNotify({
isOpen: true,
message: 'Submitted Successfully',
type: 'success'
})
}
const openInPopup = item => {
setRecordForEdit(item)
setOpenPopup(true)
}
const onDelete = id => {
setConfirmDialog({
...confirmDialog,
isOpen: false
})
supplierService.deleteEmployee(id);
setRecords(supplierService.getAllEmployees())
setNotify({
isOpen: true,
message: 'Deleted Successfully',
type: 'error'
})
}
return (
<>
<PageHeader
title= "Fornecedores"
subTitle="Tabela de Fornecedores - Novo / Atualizar"
icon={<FactoryIcon fontSize="large" text-align='center'/>}
/>
<Box sx={{width: "1060px"}}>
<Paper className={classes.pageContent}>
<Grid container direction= 'row' justifyContent="space-between" >
<Controls.Input
label="Pesquisar Fornecedor"
className={classes.searchInput}
InputProps={{
startAdornment: (<InputAdornment position="start">
<SearchIcon />
</InputAdornment>)
}}
onChange={handleSearch}
/>
<Controls.Button
text="Adicionar"
variant="outlined"
color="primary"
startIcon={<AddIcon />}
className={classes.newButton}
onClick={() => { setOpenPopup(true); setRecordForEdit(null); }}
/>
</Grid>
<TblContainer>
<TblHead />
<TableBody>
{
recordsAfterPagingAndSorting().map(item =>
(<TableRow key={item.id}>
<TableCell>{item.fullName}</TableCell>
<TableCell>{item.email}</TableCell>
<TableCell>{item.mobile}</TableCell>
<TableCell>{item.department}</TableCell>
<TableCell>
<Controls.ActionButton
color="primary"
onClick={() => { openInPopup(item) }}>
<ModeEditOutlineIcon fontSize="small" />
</Controls.ActionButton>
<Controls.ActionButton
color="secondary"
onClick={() => {
setConfirmDialog({
isOpen: true,
title: 'Are you sure to delete this record?',
subTitle: "You can't undo this operation",
onConfirm: () => { onDelete(item.id) }
})
}}>
<CloseIcon fontSize="small" />
</Controls.ActionButton>
</TableCell>
</TableRow>)
)
}
</TableBody>
</TblContainer>
**strong text** // Pagination begins here!!!!!
<TblPagination components={{
Toolbar: props => (
<div>
style={{ backgroundColor: '#a9aeb3', width: '950px', color: 'rgb(41, 39, 39)',
height: '35px' }}
</div>
)
}}/>
</Paper>
</Box>
<Popup
title="Employee Form"
openPopup={openPopup}
setOpenPopup={setOpenPopup}
>
<SupplierForm
recordForEdit={recordForEdit}
addOrEdit={addOrEdit} />
</Popup>
<Notification
notify={notify}
setNotify={setNotify}
/>
<ConfirmDialog
confirmDialog={confirmDialog}
setConfirmDialog={setConfirmDialog}
/>
</>
)
}
I've been struggling with styling the pagination component myself, but just got it working using sx.
Try with something like this:
<TablePagination
sx={{
'.MuiTablePagination-toolbar': {
backgroundColor: '#a9aeb3',
width: '950px',
color: 'rgb(41, 39, 39)',
height: '35px',
},
}}
/>
Edit:
I tried styling "everything" just to see how it would be done, look here for ideas if there was something else you needed to style.
<Pagination
{...mTablePaginationProps}
rowsPerPage={rowsPerPage}
onRowsPerPageChange={onRowsPerPageSelect}
component="div"
onPageChange={onPageChange}
sx={{
backgroundColor: 'red !important', // gets overridden if not important
height: '70px',
'.MuiInputBase-root': {
backgroundColor: 'green',
},
'.MuiTablePagination-toolbar': {
backgroundColor: 'pink',
width: '950px',
color: 'rgb(41, 39, 39)',
height: '35px',
},
'.MuiBox-root': {
backgroundColor: 'yellow',
color: 'black',
'& .MuiSvgIcon-root': {
backgroundColor: 'purple',
color: 'black',
},
},
}}
SelectProps={{
...mTablePaginationProps.SelectProps,
MenuProps: {
...mTablePaginationProps.SelectProps.MenuProps,
sx: {
'.MuiPaper-root': {
backgroundColor: 'rosybrown',
color: 'black',
},
'.MuiTablePagination-menuItem': {
':hover': {
backgroundColor: 'turquoise',
},
backgroundColor: 'yellow',
},
'.MuiTablePagination-menuItem.Mui-selected': {
':hover': {
backgroundColor: 'blue',
},
backgroundColor: 'purple',
},
},
},
}}
/>
This ends up looking like this:
const styles = makeStyles((theme) => ({
root: { margin: "0px 20px" },
textStyle: {
fontFamily: "Comfortaa",
},
container: {},
textField: {
fontFamily: "Comfortaa",
},
dropDownFormSize: {
width: "100%",
fontFamily: "Comfortaa",
},
optionDropdown: {
color: "black",
},
dropDownSelector: {
color: "black",
backgroundColor: "tomato",
},
nativeInput: {
opacity: "1",
},
}));
const MainTable: React.FC = () => {
const classes = styles();
<FormControl
classes={{
root: classes.dropDownFormSize,
}}
>
<Select
required
className={classes.dropDownSelector}
value={emotion[i]}
name="emotion"
onChange={handleChangeEmotion(i)}
classes={{
root: classes.optionDropdown,
select: classes.optionDropdown,
// using nativeInput here gives me error
nativeInput: classes.nativeInput,
}}
MenuProps={{
anchorOrigin: {
vertical: "bottom",
horizontal: "left",
},
getContentAnchorEl: null,
MenuListProps: {
className: classes.optionDropdown,
},
}}
placeholder="Select Something"
native={false}
>
<MenuItem
value=""
disabled
// className={
// classes.optionItems
// }
>
Select Emotion
</MenuItem>
{emotions.map((emotion, i) => {
return (
<MenuItem
key={i}
// className={
// classes.optionItems
// }
value={emotion}
>
{emotion}
</MenuItem>
);
})}
</Select>
</FormControl>;
};
I want to remove opacity from the .MuiSelect-nativeInput Class. When I try to override this class using the nativeInput rule, I get this error message :-
Object literal may only specify known properties, and 'nativeInput' does not exist in type 'Partial<ClassNameMap<SelectClassKey>>'. Eventhough, nativeInput rule is given in the documentation of Select API. I have tried to override it in the Theme file but again, I get the error that nativeInput does not exist. How can I remove the opacity from the MuiSelect-nativeInput class.
You can instead use a TextField rendered as a select input.
const useStyles = makeStyles({
root: {
"& .MuiSelect-nativeInput": {
opacity: 1,
},
},
});
<TextField
select
classes = {{ root: classes.root }}
/>
my material-ui text field is displaying the wrong width:
My styling:
const useStyles = makeStyles((theme) => ({
root: {
'& > *': {
margin: theme.spacing(1),
},
},
input: {
backgroundColor: "white",
},
textfield: {
color: "white",
width: "400px",
marginBottom: theme.spacing(3)
},
textfieldLabel: {
color: "white",
}
}));
My components:
return (
<div>
<form className={classes.root} noValidate autoComplete="off">
<TextField className={classes.textfield} InputProps={{className: classes.input}} InputLabelProps={{className: classes.textfieldLabel}} id="url-textfield" label="URL" variant="standard"/>
</form>
</div>
);
I have tried the default styling of the documentation and even that doesn't work. What am i doing wrong?
I am trying to accomplish this: I would like there to be text on the first image, but after that I do not want there to be. Everything I commented out is how I am doing it originally, but changed so it could be viewed for you guys. Please make note of that as it might change the insight I receive. Right now I am getting no display of text at all.
Also, if the carousel in there adds too much distraction I can take it out.
import * as React from 'react';
import {
Text,
View,
StyleSheet,
Image,
ScrollView,
Dimensions,
ImageBackground,
} from 'react-native';
import Constants from 'expo-constants';
const { width } = Dimensions.get('window');
const height = width * 0.6;
const images = [
'https://images.pexels.com/photos/2249602/pexels-photo-2249602.jpeg?cs=srgb&dl=pexels-sergio-souza-2249602.jpg&fm=jpg',
'https://images.pexels.com/photos/3178881/pexels-photo-3178881.jpeg?cs=srgb&dl=pexels-andrew-neel-3178881.jpg&fm=jpg',
'https://images.pexels.com/photos/4946412/pexels-photo-4946412.jpeg?cs=srgb&dl=pexels-maria-orlova-4946412.jpg&fm=jpg',
'https://images.pexels.com/photos/4911060/pexels-photo-4911060.jpeg?cs=srgb&dl=pexels-cottonbro-4911060.jpg&fm=jpg',
];
//this is the array I noramlly use.
//const images = [
// {id : "1", uri: require('../../assets/placeholder1.jpg'), text: "Test"},
// {id : "2", uri: require('../../assets/placeholder2.jpg'), /*text: "Test"*/},
// {id : "3", uri: require('../../assets/placeholder3.jpg'), /*text: "Test"*/},
// {id : "4", uri: require('../../assets/placeholder4.jpg'), /*text: "Test"*/},
// {id : "5", uri: require('../../assets/placeholder5.jpg'), /*text: "Test"*/},
// {id : "6", uri: require('../../assets/placeholder6.jpg'), /*text: "Test"*/},
// {id : "7", uri: require('../../assets/placeholder7.jpg'), /*text: "Test"*/},
// {id : "8", uri: require('../../assets/placeholder8.jpg'), /*text: "Test"*/},
// {id : "9", uri: require('../../assets/placeholder9.jpg'), /*text: "Test"*/},
//]
export default class App extends React.Component {
state = {
active: 0,
};
change = ({ nativeEvent }) => {
const slide = Math.ceil(
nativeEvent.contentOffset.x / nativeEvent.layoutMeasurement.width
);
if (slide !== this.state.active) {
this.setState({ active: slide });
}
};
render() {
return (
<View style={{flex: 1}}>
<View style={{ flex: 3, justifyContent: 'center', alignItems: 'center'}}>
<ScrollView
pagingEnabled
horizontal
showsHorizontalScrollIndicator={false}
onScroll={this.change}
style={{ width, height }}>
{
images.map((image, index) => (
<ImageBackground
key={index}
source={{uri: image}}
//Normally, I would not have key and source would be like this
//source={item.uri}
style={{ width, height: '100%', resizeMode: 'cover' }}>
<View style={{position: 'absolute', bottom: 25 }}>
<Text style = {this.state.active === 0 ? <Text>Placeholder</Text> : null , styles.Name}> </Text>
<Text style = {this.state.active === 0 ? <Text>Another Placeholder</Text> : null , styles.Name}> </Text>
</View>
</ImageBackground>
))
}
</ScrollView>
<View style={{flexDirection: 'row', position: 'absolute', bottom: 0, alignSelf: 'center',}}>
{
images.map((i, k) => (
<Text style={k == this.state.active ? styles.activeCorousel : styles.carousel}>
⬤
</Text>
))}
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
carousel: {
color: '#888',
fontSize: width / 35,
opacity: .5
},
activeCorousel: {
color: '#fff',
fontSize: width / 35,
},
Name: {
fontWeight: 'bold',
color: 'white',
fontSize: 40,
paddingLeft: 20
},
});
Feel free to copy my code into snack.expo.io.
Use conditional JSX to render only if the index is equal to 0.
images.map((image, index) => (
<ImageBackground
key={index}
source={{uri: image}}
style={{ width, height: '100%', resizeMode: 'cover' }}
>
{index === 0 && (
<View style={{position: 'absolute', bottom: 25 }}>
<Text>Placeholder</Text>
</View>
)}
</ImageBackground>
))
Also, your conditional styling:
<Text style = {this.state.active === 0 ? <Text>...
does not make any sense at all; style attribute does not support JSX, just only React Native valid styling props.
How can I change the color from "email" label and make it the same as the border line?
Here's my code:
import React, { Component } from "react";
import { Icon } from "semantic-ui-react";
import { Divider } from "semantic-ui-react";
import { TextField, Button, Grid } from "#material-ui/core";
import PropTypes from "prop-types";
import classNames from "classnames";
import { withStyles } from "#material-ui/core/styles";
let self;
const styles = theme => ({
container: {
display: "flex",
flexWrap: "wrap"
},
textField: {
marginLeft: theme.spacing.unit,
marginRight: theme.spacing.unit,
width: 280
},
cssLabel: {
color: "#d3d3d3"
},
cssOutlinedInput: {
"&:not(hover):not($disabled):not($cssFocused):not($error) $notchedOutline": {
borderColor: "#d3d3d3" //default
},
"&:hover:not($disabled):not($cssFocused):not($error) $notchedOutline": {
borderColor: "#d3d3d3" //hovered #DCDCDC
},
"&$cssFocused $notchedOutline": {
borderColor: "#23A5EB" //focused
}
},
cssInputLabel: {
color: "#d3d3d3"
},
notchedOutline: {},
cssFocused: {},
error: {},
disabled: {}
});
class NewLoginComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
loggedIn: false,
user: "",
errorMsg: "",
errorMsgLength: "",
loginErrorMsg: "",
flag: false,
password: "",
hidden: true,
valuePassText: "SHOW"
};
self = this;
}
componentDidMount() {
this._isMounted = true;
if (this.props.password) {
this.setState({ password: this.props.password });
}
}
componentDidUpdate(prevProps) {}
render() {
const { classes } = this.props;
let username = "";
let password = "";
return (
<div className="container-fluid backround">
<div className="container" id="loginform">
<div className="form-group">
<div>
<div className="emailInput">
<TextField
className={classes.textField}
id="email-txt-input"
label="Email"
variant="outlined"
inputRef={node => (username = node)}
InputLabelProps={{
classes: {
root: classes.cssLabel,
focused: classes.cssFocused
}
}}
InputProps={{
classes: {
root: classes.cssOutlinedInput,
focused: classes.cssFocused,
notchedOutline: classes.notchedOutline
},
inputMode: "numeric"
}}
/>
</div>
<div className="passwordInput">
<TextField
className={classes.textField}
id="password-txt-input"
label="Password"
variant="outlined"
inputRef={node => (password = node)}
type={this.state.hidden ? "password" : "text"}
value={this.state.password}
onChange={this.handlePasswordChange}
InputLabelProps={{
classes: {
root: classes.cssLabel,
focused: classes.cssFocused
}
}}
InputProps={{
classes: {
root: classes.cssOutlinedInput,
focused: classes.cssFocused,
notchedOutline: classes.notchedOutline
},
inputMode: "numeric"
}}
/>
</div>
</div>
<div className="form-group form">
<Button
variant="contained"
id="normal-signin-Btn"
type={"submit"}
className={"btn btn-primary loginButton"}
>
LogIn
</Button>
</div>
</div>
</div>
</div>
);
}
}
NewLoginComponent.propTypes = {
classes: PropTypes.object.isRequired
};
export default withStyles(styles)(NewLoginComponent);
Below is one way to control the focused color of the input label to be the same as the focused color of the border:
cssLabel: {
color: "#d3d3d3",
"&.Mui-focused": {
color: "#23A5EB"
}
},
You can simply use the InputLabelProps in your TextField component , for exemple :
<TextField InputLabelProps={{style : {color : 'green'} }}></TextField>
Try using this CSS code in your CSS file to change its border color:
.css-1d3z3hw-MuiOutlinedInput-notchedOutline{
color: yellow !important;
border: 2px solid yellow !important;
}
and to change its label you can use the following inline style in your <TextField/> :
InputLabelProps={{style : {color : 'yellow'} }}
This method should work if you still can't change it, You can also try changing its color by inspecting it from the browser.
try this: put in the TextField
sx={{
"& label": {
"&.Mui-focused": {
color: 'your color*'
}
}
}}