-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFR] Introduce <PasswordInput> #3013
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it seems you changed many files just because you run prettier on them. It makes it hard to tell the changes you made for the password input feature. Please revert the prettier changes on files you didn't modify for the password input feature - we'll fix the prettier problems in another PR.
Also, there hous not be a PasswordField, because the password should never be exposed.
224e7ce
to
b981270
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, you should simulate the hashing of the password in the server side, and the fact that a user update with no password doesn't empty the password in the server side. You can do all that in a wrapper around the data provider.
Any chance you can update that one soon? |
Yeah, I think I'll just do it in plain JavaScript since none of the inputs are in TS and that I need to use a dependency. |
OK, let's forget the TypeScript requirement |
OK, I replaced the direct password edition by a tab with two fields: password and confirm password, on both Create and Edit views. Since the demo API is a false in-memory API with only purpose to show react admin features, are we forced to handle that password hashing? PS: Screenshots have been updated on the first post. |
We use this version in one of our project. It's not TypeScript but there are hooks 😄 import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { TextInput } from 'react-admin';
import IconButton from '@material-ui/core/IconButton';
import InputAdornment from '@material-ui/core/InputAdornment';
import Visibility from '@material-ui/icons/Visibility';
import VisibilityOff from '@material-ui/icons/VisibilityOff';
const PasswordInput = ({ defaultVisible, ...otherProps }) => {
const [visible, setVisible] = useState(defaultVisible);
return (
<TextInput
{...otherProps}
type={visible ? 'text' : 'password'}
InputProps={{
endAdornment: (
<InputAdornment position="end">
<IconButton onClick={() => setVisible(!visible)}>
{visible ? <Visibility /> : <VisibilityOff />}
</IconButton>
</InputAdornment>
),
}}
/>
);
};
PasswordInput.propTypes = {
defaultVisible: PropTypes.bool,
};
PasswordInput.defaultProps = {
defaultVisible: false,
};
export default PasswordInput; |
Is it worth it to rebase this one? |
Yes, it's still worth rebasing! No need to rewrite it with hooks, but you're welcome to do so. |
b502f17
to
a7058e1
Compare
Rebased on |
8c8805c
to
4ae3bdc
Compare
Done 👌 |
Needs rebase |
2cde6c8
to
a32506b
Compare
a32506b
to
8d5ce2f
Compare
Excellent, thanks! |
This PR introduce a new component in
ra-ui-materialui
,<PasswordInput>
.It is very similar to a
<TextInput type="password">
, but it adds a button to toggle visibility.I found that it's a common need in our client projects, and it can be a great accessibility addition.
That being said, I'm willing to create a third-party library with this component if you think that this component doesn't have its place in
ra-ui-materialui
.Also, I have another proposal: apply this toggle button directly on the
TextInput
if the type is password.TODO
Previews