Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2016, 2023
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -38,8 +38,8 @@ export const Default = (args) => (
Default.args = {
defaultWidth: 300,
placeholder: 'Placeholder text',
showPasswordLabel: 'Show password label',
hidePasswordLabel: 'Hide password label',
showPasswordLabel: 'Show password',
hidePasswordLabel: 'Hide password',
onTogglePasswordVisibility: true,
invalid: false,
invalidText:
Expand Down
9 changes: 7 additions & 2 deletions packages/react/src/components/TextInput/PasswordInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ const PasswordInput = React.forwardRef(
}
);

const tooltipClasses = classNames(
`${prefix}--toggle-password-tooltip`,
`${prefix}--icon-tooltip`
);

let align: PopoverAlignment | undefined = undefined;

if (tooltipPosition === 'top' || tooltipPosition === 'bottom') {
Expand Down Expand Up @@ -370,12 +375,12 @@ const PasswordInput = React.forwardRef(

<Tooltip
align={align}
className={`${prefix}--toggle-password-tooltip`}
className={tooltipClasses}
label={passwordIsVisible ? hidePasswordLabel : showPasswordLabel}>
<button
type="button"
className={passwordVisibilityToggleClasses}
disabled={disabled || readOnly}
disabled={disabled}
onClick={handleTogglePasswordVisibility}>
{passwordVisibilityIcon}
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ describe('PasswordInput', () => {
expect(inputElement).toHaveAttribute('readonly');
});

it('should disable hide toggle button when readOnly is true', () => {
it('should not disable hide toggle button when readOnly is true', () => {
const { getByRole } = render(
<PasswordInput
id="input-1"
Expand All @@ -387,7 +387,25 @@ describe('PasswordInput', () => {
/>
);
const toggleButton = getByRole('button');
expect(toggleButton).toBeDisabled();
expect(toggleButton).not.toBeDisabled();
});

it('should allow toggling password visibility when readOnly is true', async () => {
render(
<PasswordInput
id="input-1"
labelText="TextInput label"
hidePasswordLabel="Hide Password"
showPasswordLabel="Show Password"
readOnly
/>
);

await userEvent.click(screen.getByRole('button'));
expect(screen.getByText('Hide Password')).toBeInTheDocument();

await userEvent.click(screen.getByRole('button'));
expect(screen.getByText('Show Password')).toBeInTheDocument();
});

it('should not allow input change when readOnly is true', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright IBM Corp. 2018, 2023
// Copyright IBM Corp. 2018, 2025
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -49,6 +49,11 @@
inset-inline-start: auto;
}
}
.#{$prefix}--text-input--fluid.#{$prefix}--text-input-wrapper--readonly
.#{$prefix}--text-input__field-wrapper
.#{$prefix}--text-input {
color: $text-secondary;
}

.#{$prefix}--text-input--fluid .#{$prefix}--label::-webkit-scrollbar,
.#{$prefix}--text-input--fluid
Expand Down
12 changes: 2 additions & 10 deletions packages/styles/scss/components/text-input/_text-input.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright IBM Corp. 2016, 2023
// Copyright IBM Corp. 2016, 2025
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -152,21 +152,13 @@

.#{$prefix}--btn.#{$prefix}--text-input--password__visibility__toggle.#{$prefix}--tooltip__trigger
svg {
fill: $icon-secondary;
transition: fill $duration-fast-01 motion(standard, productive);
fill: $icon-primary;
}

.#{$prefix}--btn.#{$prefix}--text-input--password__visibility__toggle.#{$prefix}--tooltip__trigger:focus {
@include focus-outline('outline');
}

.#{$prefix}--btn.#{$prefix}--text-input--password__visibility__toggle.#{$prefix}--tooltip__trigger:hover
svg,
.#{$prefix}--btn.#{$prefix}--text-input--password__visibility__toggle.#{$prefix}--tooltip__trigger:focus
svg {
fill: $icon-primary;
}

.#{$prefix}--text-input--invalid,
.#{$prefix}--text-input--warning {
padding-inline-end: $spacing-08;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,34 @@ describe('cds-password-input', () => {
expect(input.readOnly).to.be.true;
});

it('should disable hide/show password toggle button when readonly is true', async () => {
it('should not disable hide/show password toggle button when readonly is true', async () => {
const el = await fixture(html`
<cds-password-input readonly></cds-password-input>
`);
await el.updateComplete;

const toggleButton = el.shadowRoot.querySelector('button[type="button"]');
expect(toggleButton.disabled).to.be.true;
expect(toggleButton.disabled).to.be.false;
});

it('should allow toggling password visibility when readonly is true', async () => {
const el = await fixture(html`
<cds-password-input
hide-password-label="Hide Password"
show-password-label="Show Password"></cds-password-input>
`);
const btn = el.shadowRoot.querySelector('button');
const tooltipContent = el.shadowRoot.querySelector(
'cds-tooltip-content#content'
);

btn.click();
await el.updateComplete;
expect(tooltipContent.textContent.trim()).to.equal('Hide Password');

btn.click();
await el.updateComplete;
expect(tooltipContent.textContent.trim()).to.equal('Show Password');
});

it('should not allow input change when readOnly is true', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ $css--plex: true !default;
::slotted(#{$prefix}-slug:not([revert-active])) {
transform: translateY(-50%);
}

#{$prefix}-tooltip::part(popover-container) {
block-size: 100%;
inline-size: 100%;
}

.#{$prefix}--btn--icon-only {
border: none;
background-color: transparent;
block-size: 100%;
cursor: pointer;
inline-size: 100%;

&:focus {
@include focus-outline('outline');
}
}

.#{$prefix}--text-input--password__visibility__toggle svg {
pointer-events: none;
}
}

:host(#{$prefix}-password-input[warn]),
Expand All @@ -56,20 +77,3 @@ $css--plex: true !default;
position: relative;
}
}

#{$prefix}-tooltip::part(popover-container) {
block-size: 100%;
inline-size: 100%;
}

.#{$prefix}--btn--icon-only {
border: none;
background-color: transparent;
block-size: 100%;
cursor: pointer;
inline-size: 100%;

&:focus {
@include focus-outline('outline');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ const args = {
disabled: false,
helperText: 'Optional help text',
hideLabel: false,
hidePasswordLabel: 'Hide Password',
hidePasswordLabel: 'Hide password',
inline: false,
invalid: false,
invalidText: 'Error message goes here',
labelText: 'Text input label',
placeholder: 'Placeholder text',
readonly: false,
showPasswordLabel: 'Show Password',
showPasswordLabel: 'Show password',
size: INPUT_SIZE.MEDIUM,
tooltipAlignment: INPUT_TOOLTIP_ALIGNMENT.END,
tooltipPosition: INPUT_TOOLTIP_DIRECTION.BOTTOM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class CDSPasswordInput extends CDSTextInput {
* Handles password visibility toggle button click
*/
private handleTogglePasswordVisibility() {
if (this.disabled || this.readonly) return;
if (this.disabled) return;
this.type =
this.type === INPUT_TYPE.PASSWORD ? INPUT_TYPE.TEXT : INPUT_TYPE.PASSWORD;
}
Expand Down Expand Up @@ -295,9 +295,9 @@ class CDSPasswordInput extends CDSTextInput {
<cds-tooltip
align="${align}"
class="${passwordVisibilityTooltipClasses}"
?disabled="${normalizedProps.disabled || readonly}">
?disabled="${normalizedProps.disabled}">
<button
?disabled="${normalizedProps.disabled || readonly}"
?disabled="${normalizedProps.disabled}"
type="button"
role="button"
class="${passwordVisibilityButtonClasses}"
Expand All @@ -307,7 +307,7 @@ class CDSPasswordInput extends CDSTextInput {
</button>
<cds-tooltip-content
id="content"
?hidden="${normalizedProps.disabled || readonly}">
?hidden="${normalizedProps.disabled}">
${passwordIsVisible
? this.hidePasswordLabel
: this.showPasswordLabel}
Expand All @@ -326,7 +326,14 @@ class CDSPasswordInput extends CDSTextInput {
</div>
`;
}

firstUpdated() {
this.updateComplete.then(() => {
this.shadowRoot
?.querySelector(`${prefix}-tooltip`)
?.shadowRoot?.querySelector(`.${prefix}--tooltip`)
?.classList.add(`${prefix}--icon-tooltip`);
});
}
/**
* A selector that will return the slug item.
*
Expand Down