最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - On Page Load, the saved credentials are auto filled and they are overlaping with the placeholder of mui textfield comp

programmeradmin3浏览0评论

On Page Load, the saved credentials are auto filled and they are overlaping with the placeholder of mui textfield component

How to solve this

I used useEffect for triggering click event on page render , but its not effecting the text field, and i tried autoFocus prop also , its not working too

<TextField
        id={id}
        fullWidth
        autoFocus={autofocus}
        name={name}
        style={customStyles}
        label={label}
        variant={variant}
        type={showPassword ? "text" : type}
        value={value}
        onChange={handleOnChange}
        onBlur={onBlur}
        error={error}
        helperText={helperText}
        placeholder={placeholder} 
        onKeyDown={handleKeyDown}
        slotProps={{
          input: {
            autoComplete: autocomplete,
            ...(type === "password" && {
              endAdornment: (
                <InputAdornment position="end">
                  <IconButton
                    aria-label={
                      showPassword
                        ? "hide the password"
                        : "display the password"
                    }
                    onClick={handleClickShowPassword}
                    onMouseDown={handleMouseDownPassword}
                    onMouseUp={handleMouseUpPassword}
                    edge="end"
                  >
                    {showPassword ? (
                      <VisibilityOff titleAccess={t(wordings.hidePassword)} />
                    ) : (
                      <Visibility titleAccess={t(wordings.showPassword)} />
                    )}
                  </IconButton>
                </InputAdornment>
              ),
            }),
          },
        }}

On Page Load, the saved credentials are auto filled and they are overlaping with the placeholder of mui textfield component

How to solve this

I used useEffect for triggering click event on page render , but its not effecting the text field, and i tried autoFocus prop also , its not working too

<TextField
        id={id}
        fullWidth
        autoFocus={autofocus}
        name={name}
        style={customStyles}
        label={label}
        variant={variant}
        type={showPassword ? "text" : type}
        value={value}
        onChange={handleOnChange}
        onBlur={onBlur}
        error={error}
        helperText={helperText}
        placeholder={placeholder} 
        onKeyDown={handleKeyDown}
        slotProps={{
          input: {
            autoComplete: autocomplete,
            ...(type === "password" && {
              endAdornment: (
                <InputAdornment position="end">
                  <IconButton
                    aria-label={
                      showPassword
                        ? "hide the password"
                        : "display the password"
                    }
                    onClick={handleClickShowPassword}
                    onMouseDown={handleMouseDownPassword}
                    onMouseUp={handleMouseUpPassword}
                    edge="end"
                  >
                    {showPassword ? (
                      <VisibilityOff titleAccess={t(wordings.hidePassword)} />
                    ) : (
                      <Visibility titleAccess={t(wordings.showPassword)} />
                    )}
                  </IconButton>
                </InputAdornment>
              ),
            }),
          },
        }}
Share Improve this question asked Mar 6 at 4:56 Athul KrishnanAthul Krishnan 213 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Read the MUI documentation

To workaround the issue, you can force the "shrink" state of the label.

<TextField slotProps={{ inputLabel: { shrink: true } }} />

or

<InputLabel shrink>Count</InputLabel>
发布评论

评论列表(0)

  1. 暂无评论