我有一个在对话框中使用MUI窗体的窗体,由于某种原因,Textfield永远不会具有标准的变体外观.它始终具有填充的边框.更奇怪的是,我试图添加来自NextUi库的输入,但我无法go 掉输入中的一个框(我假设是因为全局Mui样式而被迫出现在那里的?).我放在网站上的每一个文本字段都有这个,甚至自动补全组件也有这个.这种全球性的梅花风格会影响到这一点吗?我不能用我try 过的任何样式覆盖它.

This is the Form (Just the base taken right from MUI docs as you can see that Standard one is not standard):

import * as React from 'react';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';

export default function AddInfoForm() {
    return (
        <Box
            component="form"
            sx={{
                '& > :not(style)': { m: 1, width: '25ch' },
            }}
            noValidate
            autoComplete="off"
        >
            <TextField id="outlined-basic" label="Outlined" variant="outlined" />
            <TextField id="filled-basic" label="Filled" variant="filled" />
            <TextField id="standard-basic" label="Standard" variant="standard" />
        </Box>
    );
}

This is the component its in (I know its a mess right now):

import { useState, useRef } from 'react';
import { GoogleAuthProvider, signInWithPopup, RecaptchaVerifier, signInWithPhoneNumber } from 'firebase/auth';
import { auth } from '../../utils/Auth/FirebaseConfig';
import { Stepper, Step, StepLabel, Button, Typography, SvgIcon, TextField, Box, Modal, Dialog, DialogContent, useMediaQuery, useTheme, CssBaseline } from '@mui/material';
import { makeStyles } from '@mui/styles';
import AuthService from '../../services/auth.service';
import 'react-phone-number-input/style.css'
import PhoneInput from 'react-phone-number-input'
import AddInfoForm from './AddInfoForm';

const useStyles = makeStyles((theme) => ({
    googleButton: {
        userSelect: 'none',
        WebkitAppearance: 'none',
        backgroundColor: 'white',
        backgroundImage: 'none',
        border: '1px solid #747775',
        borderRadius: '4px',
        boxSizing: 'border-box',
        color: '#1f1f1f',
        cursor: 'pointer',
        fontFamily: "'Roboto', arial, sans-serif",
        fontSize: '14px',
        height: '40px',
        letterSpacing: '0.25px',
        outline: 'none',
        overflow: 'hidden',
        padding: '0 12px',
        position: 'relative',
        textAlign: 'center',
        transition: 'background-color .218s, border-color .218s, box-shadow .218s',
        verticalAlign: 'middle',
        whiteSpace: 'nowrap',
        maxWidth: '400px',
        minWidth: 'min-content',
        '&:hover': {
            boxShadow: '0 1px 2px 0 rgba(60, 64, 67, .30), 0 1px 3px 1px rgba(60, 64, 67, .15)'
        },
        // other styles for different states
    },
    googleIcon: {
        height: '20px',
        marginRight: '12px',
        minWidth: '20px',
        width: '20px'
    },
    // other styles for different parts of the button
}));

// Define the steps
const steps = ['Personal Information', 'Contact Information', 'Account Preferences', 'Security Settings', 'Terms and Agreements'];

// Define a component for each step
const StepContent = ({ step }) => {
    switch (step) {
        case 0:
            return <div>Personal Information Form</div>; // Replace with your form component
        case 1:
            return <div>Contact Information Form</div>; // Replace with your form component
        case 2:
            return <div>Account Preferences Form</div>; // Replace with your form component
        case 3:
            return <div>Security Settings Form</div>; // Replace with your form component
        case 4:
            return <div>Terms and Agreements</div>; // Replace with your form component
        default:
            return <div>Unknown Step</div>;
    }
};

const Signup = () => {
    const [isFormModalOpen, setIsFormModalOpen] = useState(true);
    const [formStep, setFormStep] = useState(0);
    const [phoneNumber, setPhoneNumber] = useState('');
    const [verificationCode, setVerificationCode] = useState('');
    const [isModalOpen, setIsModalOpen] = useState(false);
    const [type, setType] = useState('');
    const recaptchaVerifier = useRef(null);

    const openMultiStepForm = () => {
        setIsFormModalOpen(true);
        setFormStep(0); // Start from the first step
    };

    const handleGoogleSignUp = async () => {
        const provider = new GoogleAuthProvider();
        try {
            const result = await signInWithPopup(auth, provider);
            const user = result.user;
            setType('google');
            sendUserToBackend(user);
        } catch (error) {
            // Handle Errors here.
            console.error(error);
        }
    };

    const sendUserToBackend = async (user) => {
        const email = user.email;
        const displayName = user.displayName;
        const uid = user.uid;
        const phoneNumber = user.phoneNumber
        try {
            // Check if the user already exists in MongoDB
            const existingUser = await AuthService.checkIfUserExists(uid);
            console.log(existingUser)

            if (existingUser.data.message === 'User not found') {
                // If user does not exist, create a new user in MongoDB
                const response = await AuthService.createFirebaseUser(email, displayName, uid, type, phoneNumber);
                if (response.status === 200) {
                    openMultiStepForm();
                }

                console.log('New user created in backend:', response.data);
            } else {
                console.log('User already exists, signed in successfully');
            }
        } catch (error) {
            console.error('Error handling user data:', error);
        }
    };

    const setUpRecaptcha = () => {
        window.recaptchaVerifier = new RecaptchaVerifier('sign-in-button', {
            'size': 'invisible',
            'callback': (response) => {
                // reCAPTCHA solved, allow phone sign in
                handleSMSLogin();
            }
        }, auth);
    };

    const handleSMSLogin = async () => {
        setType('phone')
        if (!recaptchaVerifier.current) {
            recaptchaVerifier.current = new RecaptchaVerifier(auth, 'sign-in-button', {
                'size': 'invisible',
                'callback': (response) => {
                    // reCAPTCHA solved, allow phone sign in
                }
            });
        }

        const appVerifier = recaptchaVerifier.current;
        try {
            const confirmationResult = await signInWithPhoneNumber(auth, phoneNumber, appVerifier);
            window.confirmationResult = confirmationResult;
            setIsModalOpen(true); // Open the modal for verification code input
        } catch (error) {
            console.error("Error during SMS authentication", error);
        }
    };

    // const handleSMSLogin = async () => {
    //     setUpRecaptcha();
    //     const appVerifier = recaptchaVerifier.current;
    //     try {
    //         const confirmationResult = await signInWithPhoneNumber(auth, phoneNumber, appVerifier);
    //         window.confirmationResult = confirmationResult;
    //         setIsModalOpen(true); // Open the modal for verification code input
    //     } catch (error) {
    //         console.error("Error during SMS authentication", error);
    //     }
    // };

    const verifyCode = async () => {
        try {
            const result = await window.confirmationResult.confirm(verificationCode);
            const user = result.user;
            setType('phone');
            sendUserToBackend(user);
            setIsModalOpen(false); // Close the modal after verification
        } catch (error) {
            console.error("Error verifying the code", error);
        }
    };

    // Google Icon as an SVG component
    const GoogleIcon = (props) => (
        <SvgIcon viewBox="0 0 48 48">
            <path fill="#EA4335" d="M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z"></path>
            <path fill="#4285F4" d="M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z"></path>
            <path fill="#FBBC05" d="M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z"></path>
            <path fill="#34A853" d="M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z"></path>
            <path fill="none" d="M0 0h48v48H0z"></path>
        </SvgIcon>
    );

    const MultiStepForm = () => {
        const [activeStep, setActiveStep] = useState(0);
        const [open, setOpen] = useState(true);
        const theme = useTheme();
        const fullScreen = useMediaQuery(theme.breakpoints.down('md'));
        const isLastStep = activeStep === steps.length - 1;

        const handleClose = () => {
            setOpen(false);
        };

        const handleNext = () => {
            setActiveStep((prevActiveStep) => prevActiveStep + 1);
        };

        const handleBack = () => {
            setActiveStep((prevActiveStep) => prevActiveStep - 1);
        };


        const handleSubmit = () => {
            // Handle final form submission
            setIsFormModalOpen(false);
        };

        return (
            <>
                <CssBaseline />
                <Dialog
                    fullScreen={fullScreen}
                    open={open}
                    onClose={handleClose}
                    aria-labelledby="responsive-dialog-title"
                >
                    <Box sx={{ width: '100%' }}>
                        <Stepper activeStep={activeStep}>
                            {steps.map((label) => (
                                <Step key={label}>
                                    <StepLabel>{label}</StepLabel>
                                </Step>
                            ))}
                        </Stepper>
                        <div>
                            {activeStep === steps.length ? (
                                <div>
                                    <Typography sx={{ mt: 2, mb: 1 }}>
                                        All steps completed - you&apos;re finished
                                    </Typography>
                                    <Button onClick={() => setActiveStep(0)}>Reset</Button>
                                </div>
                            ) : (
                                <div>
                                    <Typography sx={{ mt: 2, mb: 1 }}>Step {activeStep + 1}</Typography>
                                    <StepContent step={activeStep} />

                                    {/* Content */}
                                    <DialogContent>
                                        <AddInfoForm />
                                    </DialogContent>
                                    <Box sx={{ display: 'flex', flexDirection: 'row', pt: 2 }}>
                                        <Button
                                            color="inherit"
                                            disabled={activeStep === 0}
                                            onClick={handleBack}
                                            sx={{ mr: 1 }}
                                        >
                                            Back
                                        </Button>
                                        <Box sx={{ flex: '1 1 auto' }} />
                                        <Button onClick={handleNext}>
                                            {activeStep === steps.length - 1 ? 'Finish' : 'Next'}
                                        </Button>
                                    </Box>
                                </div>
                            )}
                        </div>
                    </Box>
                </Dialog>
            </>
        );
    };

    const classes = useStyles();

    return (
        <>
            <Box sx={{ display: 'flex', flexDirection: 'column' }}>
                <PhoneInput
                    placeholder="Phone number"
                    value={phoneNumber}
                    onChange={(newPhoneNumber) => setPhoneNumber(newPhoneNumber)} />
                {/* <TextField
                    label="Phone Number"
                    value={phoneNumber}
                    onChange={(e) => setPhoneNumber(e.target.value)}
                    fullWidth
                    margin="normal"
                /> */}
                <Button onClick={handleSMSLogin} id="sign-in-button">Continue</Button>
                <Button
                    variant="contained"
                    className={classes.googleButton}
                    startIcon={<GoogleIcon className={classes.googleIcon} />}
                    onClick={handleGoogleSignUp}
                >
                    Sign in with Google
                </Button>
            </Box>
            {/* VERIFICATION MODAL */}
            <Modal
                open={isModalOpen}
                onClose={() => setIsModalOpen(false)}
                aria-labelledby="sms-verification-modal"
                aria-describedby="modal-for-sms-code-verification"
            >
                <Box className={classes.modal}>
                    <h2 id="sms-verification-modal">Enter Verification Code</h2>
                    <TextField
                        label="Verification Code"
                        value={verificationCode}
                        onChange={(e) => setVerificationCode(e.target.value)}
                        fullWidth
                        margin="normal"
                    />
                    <Button onClick={verifyCode}>Verify Code</Button>
                </Box>
            </Modal>

            <MultiStepForm />
        </>
    );
};

export default Signup;

This is the index.js to wrap my app:

import { useEffect } from "react";
import App from './App';
import ReactDOM from 'react-dom';
import { BrowserRouter } from "react-router-dom";
import { ThemeProvider, createTheme } from "@mui/material";
import StyledEngineProvider from "@mui/material/StyledEngineProvider";
import { NextUIProvider } from '@nextui-org/react'
import { QueryClient, QueryClientProvider } from "react-query";
import { UploadProvider } from './services/UploadContext';
import { HistoryProvider } from "./services/HistoryContext";
import { FirebaseProvider } from "./utils/Auth/FirebaseContext";

const delay = () => import(`mapbox-gl/dist/mapbox-gl.css`)
setTimeout(() => delay(), 100);


const initGA = async () => {
  if (process.env.NODE_ENV === 'production') {
    const { default: ReactGA } = await import("react-ga4");
    ReactGA.initialize("G-*******");
  }
};

const theme = createTheme({
  buttons: {
    booking: 'success'
  },
  typography: {
    fontFamily: "'Quicksand', sans-serif",
  },
});

const queryClient = new QueryClient();

const MainApp = () => {
  useEffect(() => {
    initGA();
  }, []);
  return (
    <QueryClientProvider client={queryClient}>
      <StyledEngineProvider injectFirst>
        <NextUIProvider>
          <ThemeProvider theme={theme}>
            <BrowserRouter>
              <HistoryProvider>
                <UploadProvider>
                  <FirebaseProvider>
                    <App />
                  </FirebaseProvider>
                </UploadProvider>
              </HistoryProvider>
            </BrowserRouter>
          </ThemeProvider>
        </NextUIProvider>
      </StyledEngineProvider>
    </QueryClientProvider>
  )
};

const rootElement = document.getElementById('root');
if (rootElement.hasChildNodes()) {
  ReactDOM.hydrate(<MainApp />, rootElement);
} else {
  ReactDOM.render(<MainApp />, rootElement);
}


// ReactDOM.render(<MainApp />, document.getElementById('root'));

Attached is how the form looks currently:

如有任何帮助,不胜感激!

我试图用内联样式或SX覆盖它,但没有任何效果.我试图注释掉NextUi提供程序,但没有奏效.我try 了Make Styles,它在某些方面很管用,但没有达到预期的效果.我try 使用CssBaseline,但不起作用.我试图超越主旋律,但这并不奏效.

推荐答案

只是更新一下,我想通了.我不小心在使用该表单的地方导入了第二个表单.这导致了一个造型问题.

Css相关问答推荐

VueJS CSS动画不会扩展到v-card/v-col之外

如何为多个背景和棋盘设置不同的大小

本机CSS嵌套混乱

SVG样式中的CSS类名是否是全局的?

Tailwind CSS 不输出背景类

在变量中存储匹配 Select 器的子元素的计数

CSS Select 器在 rvest 中找到,在 RSelenium 中找不到

Tailwind css 和 Next.js 导航组件 z-index 不工作

如何在流线型多页面应用程序中在表情符号和页面名称之间留出一些空白

如何为柔和的配色方案提供易于使用的高对比度替代方案?

从 Angular SCSS 生成 CSS?

有没有办法让 mui v5 呈现没有 css-xxx 前缀的类名?

为什么不能将特定于供应商的伪元素/类组合成一个规则集?

控制表格单元格之间的间距

CSS nth-child 表示大于和小于

CSS:在图像周围创建白光

谷歌浏览器两种元素样式的区别

在 Twitter Bootstrap 中创建圆角的正确方法

如何仅在一侧设置 CSS 边框?

如何使用 CSS 消除元素的偏移量?