Skip to content

Commit 3be466f

Browse files
feat: readonly state for password input (#2976)
Co-authored-by: Akshat Patel <[email protected]>
1 parent eb64d50 commit 3be466f

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/input/password-input-label.component.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,17 @@ export class PasswordInputLabelComponent extends BaseIconButton implements After
200200
/**
201201
* Reference to the wrapper element.
202202
*/
203-
@ViewChild("wrapper") wrapper: ElementRef<HTMLDivElement>;
203+
@ViewChild("wrapper", { static: true }) wrapper: ElementRef<HTMLDivElement>;
204204

205205
/**
206206
* Binding for applying class to host element.
207207
*/
208208
@HostBinding("class.cds--form-item") labelClass = true;
209209
@HostBinding("class.cds--password-input-wrapper") passwordInputWrapper = true;
210210
@HostBinding("class.cds--text-input-wrapper") textInputWrapper = true;
211+
@HostBinding("class.cds--text-input-wrapper--readonly") get isReadonly() {
212+
return this.wrapper?.nativeElement.querySelector("input")?.readOnly;
213+
}
211214

212215
/**
213216
* Constructor for PasswordInputLabelComponent.

src/input/password.stories.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* tslint:disable variable-name */
22

3-
import { moduleMetadata, Meta } from "@storybook/angular";
4-
import { InputModule, PasswordInputLabelComponent } from ".";
53
import { FormsModule } from "@angular/forms";
4+
import { Meta, moduleMetadata } from "@storybook/angular";
5+
import { InputModule, PasswordInputLabelComponent } from ".";
66

77
export default {
88
title: "Components/Input/Password",
@@ -34,7 +34,8 @@ const Template = (args) => ({
3434
[disabled]="disabled"
3535
[theme]="theme"
3636
[placeholder]="placeholder"
37-
[autocomplete]="autocomplete">
37+
[autocomplete]="autocomplete"
38+
[readonly]="readonly">
3839
</cds-password-label>
3940
`
4041
});
@@ -50,7 +51,8 @@ Basic.args = {
5051
placeholder: "Placeholder",
5152
autocomplete: "on",
5253
theme: "dark",
53-
size: "md"
54+
size: "md",
55+
readonly: false
5456
};
5557
Basic.argTypes = {
5658
autocomplete: {

0 commit comments

Comments
 (0)