Skip to content

Commit 83ecc8d

Browse files
authored
fix(PasswordInput): disable visibility toggle when input is disabled (#7482)
* fix(PasswordInput): disable visibility toggle when input is disabled * test(PasswordInput): enable input
1 parent 57017f0 commit 83ecc8d

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

packages/components/src/components/text-input/_text-input.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@
151151
+ .#{$prefix}--text-input--password__visibility__toggle
152152
svg {
153153
cursor: not-allowed;
154-
opacity: 0.5;
154+
fill: $disabled-02;
155+
156+
&:hover {
157+
fill: $disabled-02;
158+
}
155159
}
156160

157161
//-----------------------------

packages/react/src/components/TextInput/PasswordInput-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ describe('PasswordInput', () => {
100100

101101
it('should set password visibility toggle text as expected', () => {
102102
const { hidePasswordLabel, showPasswordLabel } = wrapper.props();
103+
wrapper.setProps({ disabled: false });
103104
expect(
104105
wrapper.find('.bx--text-input--password__visibility__toggle').text()
105106
).toEqual(showPasswordLabel);

packages/react/src/components/TextInput/PasswordInput.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const PasswordInput = React.forwardRef(function PasswordInput(
1111
{
1212
labelText,
1313
className,
14+
disabled,
1415
id,
1516
placeholder,
1617
onChange,
@@ -46,12 +47,12 @@ const PasswordInput = React.forwardRef(function PasswordInput(
4647
const sharedTextInputProps = {
4748
id,
4849
onChange: (evt) => {
49-
if (!other.disabled) {
50+
if (!disabled) {
5051
onChange(evt);
5152
}
5253
},
5354
onClick: (evt) => {
54-
if (!other.disabled) {
55+
if (!disabled) {
5556
onClick(evt);
5657
}
5758
},
@@ -63,10 +64,10 @@ const PasswordInput = React.forwardRef(function PasswordInput(
6364
};
6465
const labelClasses = classNames(`${prefix}--label`, {
6566
[`${prefix}--visually-hidden`]: hideLabel,
66-
[`${prefix}--label--disabled`]: other.disabled,
67+
[`${prefix}--label--disabled`]: disabled,
6768
});
6869
const helperTextClasses = classNames(`${prefix}--form__helper-text`, {
69-
[`${prefix}--form__helper-text--disabled`]: other.disabled,
70+
[`${prefix}--form__helper-text--disabled`]: disabled,
7071
});
7172
const label = labelText ? (
7273
<label htmlFor={id} className={labelClasses}>
@@ -86,10 +87,12 @@ const PasswordInput = React.forwardRef(function PasswordInput(
8687
);
8788
const passwordVisibilityToggleClasses = classNames(
8889
`${prefix}--text-input--password__visibility__toggle`,
90+
`${prefix}--btn`,
8991
`${prefix}--btn--icon-only`,
9092
`${prefix}--tooltip__trigger`,
9193
`${prefix}--tooltip--a11y`,
9294
{
95+
[`${prefix}--btn--disabled`]: disabled,
9396
[`${prefix}--tooltip--${tooltipPosition}`]: tooltipPosition,
9497
[`${prefix}--tooltip--align-${tooltipAlignment}`]: tooltipAlignment,
9598
}
@@ -98,15 +101,19 @@ const PasswordInput = React.forwardRef(function PasswordInput(
98101
<>
99102
<input
100103
{...textInputProps({ invalid, sharedTextInputProps, errorId })}
104+
disabled={disabled}
101105
data-toggle-password-visibility={inputType === 'password'}
102106
/>
103107
<button
104108
type="button"
105109
className={passwordVisibilityToggleClasses}
110+
disabled={disabled}
106111
onClick={togglePasswordVisibility}>
107-
<span className={`${prefix}--assistive-text`}>
108-
{passwordIsVisible ? hidePasswordLabel : showPasswordLabel}
109-
</span>
112+
{!disabled && (
113+
<span className={`${prefix}--assistive-text`}>
114+
{passwordIsVisible ? hidePasswordLabel : showPasswordLabel}
115+
</span>
116+
)}
110117
{passwordVisibilityIcon}
111118
</button>
112119
</>

0 commit comments

Comments
 (0)