Skip to content

Commit 8c89e7e

Browse files
committed
prevent tabbing into input when locked
1 parent 15baec9 commit 8c89e7e

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

packages/uui-input-lock/lib/uui-input-lock.element.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,37 @@ export class UUIInputLockElement extends UUIInputElement {
2222
* @default true
2323
*/
2424
@property({ type: Boolean, reflect: true })
25-
public locked: boolean = true;
25+
public get locked(): boolean {
26+
return this.#locked;
27+
}
28+
public set locked(lock: boolean) {
29+
this.#locked = lock;
30+
this.tabIndex = lock ? -1 : 0;
31+
}
32+
#locked: boolean = true;
33+
34+
/**
35+
* Define the label for the unlock button.
36+
* @type {string}
37+
* @attr
38+
* @default true
39+
*/
40+
@property({ type: String, reflect: false, attribute: 'unlock-label' })
41+
public unlockLabel: string = 'Unlock input';
42+
43+
/**
44+
* Define the label for the lock button.
45+
* @type {string}
46+
* @attr
47+
* @default true
48+
*/
49+
@property({ type: String, reflect: false, attribute: 'lock-label' })
50+
public lockLabel: string = 'Lock input';
2651

2752
constructor() {
2853
super();
2954
this.readonly = true;
55+
this.tabIndex = -1;
3056
}
3157

3258
connectedCallback(): void {
@@ -40,6 +66,9 @@ export class UUIInputLockElement extends UUIInputElement {
4066
this.readonly = this.locked = !this.locked;
4167
this.pristine = false;
4268
this.dispatchEvent(new UUIInputLockEvent(UUIInputLockEvent.LOCK_CHANGE));
69+
if (!this.locked) {
70+
this.shadowRoot?.querySelector('input')?.focus();
71+
}
4372
}
4473

4574
renderIcon() {
@@ -56,7 +85,7 @@ export class UUIInputLockElement extends UUIInputElement {
5685
@click=${this._onLockToggle}
5786
compact
5887
id="lock"
59-
label="${this.locked ? 'Unlock input' : 'Lock input'}">
88+
label="${this.locked ? this.unlockLabel : this.lockLabel}">
6089
${this.renderIcon()}
6190
</uui-button>`;
6291
}

0 commit comments

Comments
 (0)