Skip to content
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

PasswordField - adding a new prop to render the "Show/Hide" button #2759

Merged
merged 5 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/twelve-months-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-uikit/password-field': patch
---

Adding a prop to `PasswordField` that determines whether to render the "Show/Hide" button for password.
1 change: 1 addition & 0 deletions packages/components/fields/password-field/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default Example;
| `onInfoButtonClick` | `Function`<br/>[See signature.](#signature-onInfoButtonClick) | | | Function called when info button is pressed.&#xA;<br />&#xA;Info button will only be visible when this prop is passed. |
| `hintIcon` | `ReactElement` | | | Icon to be displayed beside the hint text.&#xA;<br />&#xA;Will only get rendered when `hint` is passed as well. |
| `badge` | `ReactNode` | | | Badge to be displayed beside the label.&#xA;<br />&#xA;Might be used to display additional information about the content of the field (E.g verified email) |
| `renderShowHideButton` | `boolean` | | `true` | |

## Signatures

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ storiesOf('Components|Fields', module)
}
hintIcon={hintIcon}
badge={text('badge', '')}
renderShowHideButton={boolean('renderShowHideButton', true)}
/>
);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ export type TPasswordField = {
* Might be used to display additional information about the content of the field (E.g verified email)
*/
badge?: ReactNode;
// Determines whether to render the "Show/Hide" button for the password field.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we typically use JSDoc notation for comments here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh great catch! Thanks @kark - f6691c8.

renderShowHideButton?: boolean;
};

type TTogglePasswordVisibilityHandler = (
Expand All @@ -185,8 +187,12 @@ type TTogglePasswordVisibilityHandler = (
| KeyboardEvent<HTMLButtonElement>
) => void;

const defaultProps: Pick<TPasswordField, 'horizontalConstraint'> = {
const defaultProps: Pick<
TPasswordField,
'horizontalConstraint' | 'renderShowHideButton'
> = {
horizontalConstraint: 'scale',
renderShowHideButton: true,
};

const PasswordField = (props: TPasswordField) => {
Expand All @@ -195,7 +201,8 @@ const PasswordField = (props: TPasswordField) => {
const id = useFieldId(props.id, sequentialId);
const hasError = props.touched && hasErrors(props.errors);
const hasWarning = props.touched && hasWarnings(props.warnings);
const canInteract = !props.isDisabled && !props.isReadOnly;
const canInteract =
!props.isDisabled && !props.isReadOnly && props.renderShowHideButton;

if (!props.isReadOnly) {
warning(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,14 @@ export const component = () => (
renderWarning={() => 'Custom warning'}
/>
</Spec>
<Spec label="with not rendered show/hide password button">
<PasswordField
title="Welcome Text"
value={value}
onChange={() => {}}
horizontalConstraint={7}
renderShowHideButton={false}
/>
</Spec>
</Suite>
);