Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
Expand Up @@ -375,7 +375,7 @@ const PasswordInput = React.forwardRef(
<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
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 @@ -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 Down
Loading