Skip to content

Commit

Permalink
[docs] Prevent password field blur when adornment clicked (#16672)
Browse files Browse the repository at this point in the history
* [docs] Prevent password field blur when adornment clicked

* codecov doesnt care about merge commits
  • Loading branch information
Egor Egorov authored and oliviertassinari committed Jul 25, 2019
1 parent 5860ca2 commit d4c7c05
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export default function FilledInputAdornments() {
setValues({ ...values, showPassword: !values.showPassword });
};

const handleMouseDownPassword = event => {
event.preventDefault();
};

return (
<div className={classes.root}>
<TextField
Expand Down Expand Up @@ -120,6 +124,7 @@ export default function FilledInputAdornments() {
edge="end"
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
>
{values.showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export default function FilledInputAdornments() {
setValues({ ...values, showPassword: !values.showPassword });
};

const handleMouseDownPassword = (event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();
};

return (
<div className={classes.root}>
<TextField
Expand Down Expand Up @@ -130,6 +134,7 @@ export default function FilledInputAdornments() {
edge="end"
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
>
{values.showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
Expand Down
10 changes: 9 additions & 1 deletion docs/src/pages/components/text-fields/InputAdornments.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export default function InputAdornments() {
setValues({ ...values, showPassword: !values.showPassword });
};

const handleMouseDownPassword = event => {
event.preventDefault();
};

return (
<div className={classes.root}>
<TextField
Expand Down Expand Up @@ -118,7 +122,11 @@ export default function InputAdornments() {
onChange={handleChange('password')}
endAdornment={
<InputAdornment position="end">
<IconButton aria-label="toggle password visibility" onClick={handleClickShowPassword}>
<IconButton
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
>
{values.showPassword ? <Visibility /> : <VisibilityOff />}
</IconButton>
</InputAdornment>
Expand Down
10 changes: 9 additions & 1 deletion docs/src/pages/components/text-fields/InputAdornments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export default function InputAdornments() {
setValues({ ...values, showPassword: !values.showPassword });
};

const handleMouseDownPassword = (event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();
};

return (
<div className={classes.root}>
<TextField
Expand Down Expand Up @@ -128,7 +132,11 @@ export default function InputAdornments() {
onChange={handleChange('password')}
endAdornment={
<InputAdornment position="end">
<IconButton aria-label="toggle password visibility" onClick={handleClickShowPassword}>
<IconButton
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
>
{values.showPassword ? <Visibility /> : <VisibilityOff />}
</IconButton>
</InputAdornment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export default function OutlinedInputAdornments() {
setValues({ ...values, showPassword: !values.showPassword });
};

const handleMouseDownPassword = event => {
event.preventDefault();
};

return (
<div className={classes.root}>
<TextField
Expand Down Expand Up @@ -120,6 +124,7 @@ export default function OutlinedInputAdornments() {
edge="end"
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
>
{values.showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export default function OutlinedInputAdornments() {
setValues({ ...values, showPassword: !values.showPassword });
};

const handleMouseDownPassword = (event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();
};

return (
<div className={classes.root}>
<TextField
Expand Down Expand Up @@ -130,6 +134,7 @@ export default function OutlinedInputAdornments() {
edge="end"
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
>
{values.showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
Expand Down

0 comments on commit d4c7c05

Please sign in to comment.