Skip to content

Commit c2f993b

Browse files
authored
Feat: Input Lock Event & Media Card Name (#806)
1 parent d3a7c76 commit c2f993b

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

packages/uui-card-media/lib/uui-card-media.element.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ export class UUICardMediaElement extends UUICardElement {
174174
font-size: var(--uui-type-small-size);
175175
box-sizing: border-box;
176176
padding: var(--uui-size-2) var(--uui-size-4);
177+
text-align: left;
178+
word-break: break-word;
177179
}
178180
179181
:host([disabled]) #open-part {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { UUIEvent } from '@umbraco-ui/uui-base/lib/events';
2+
import { UUIInputLockElement } from './uui-input-lock.element';
3+
4+
export class UUIInputLockEvent extends UUIEvent<{}, UUIInputLockElement> {
5+
public static readonly LOCK_CHANGE: string = 'lock-change';
6+
7+
constructor(evName: string, eventInit: any | null = {}) {
8+
super(evName, {
9+
...{ bubbles: true },
10+
...eventInit,
11+
});
12+
}
13+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
iconUnlock,
88
} from '@umbraco-ui/uui-icon-registry-essential/lib/svgs';
99
import { property } from 'lit/decorators.js';
10+
import { UUIInputLockEvent } from './UUIInputLockEvent';
1011

1112
/**
1213
* @element uui-input-lock
@@ -37,6 +38,8 @@ export class UUIInputLockElement extends UUIInputElement {
3738

3839
_onLockToggle() {
3940
this.readonly = this.locked = !this.locked;
41+
this.pristine = false;
42+
this.dispatchEvent(new UUIInputLockEvent(UUIInputLockEvent.LOCK_CHANGE));
4043
}
4144

4245
renderIcon() {

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { expect, fixture, html } from '@open-wc/testing';
1+
import { expect, fixture, html, oneEvent } from '@open-wc/testing';
22
import { UUIInputElement } from '@umbraco-ui/uui-input/lib';
33
import '@umbraco-ui/uui-icon/lib';
44
import '@umbraco-ui/uui-button/lib';
55

66
import { UUIInputLockElement } from './uui-input-lock.element';
7+
import { UUIInputLockEvent } from './UUIInputLockEvent';
78

89
describe('UUIInputLockElement', () => {
910
let element: UUIInputLockElement;
@@ -45,4 +46,21 @@ describe('UUIInputLockElement', () => {
4546
await toggle.click();
4647
await expect(element.readonly).to.be.true;
4748
});
49+
50+
it('emits lock change event', async () => {
51+
const listener = oneEvent(element, UUIInputLockEvent.LOCK_CHANGE, false);
52+
53+
const toggle = element.shadowRoot?.querySelector(
54+
'#lock',
55+
) as HTMLButtonElement;
56+
await toggle.click();
57+
58+
const event = await listener;
59+
60+
expect(event).to.exist;
61+
expect(event.type).to.equal(UUIInputLockEvent.LOCK_CHANGE);
62+
expect(event.bubbles).to.be.true;
63+
expect(event.composed).to.be.false;
64+
expect(event!.target).to.equal(element);
65+
});
4866
});

0 commit comments

Comments
 (0)