Skip to content

Commit

Permalink
Feat: Input Lock Event & Media Card Name (#806)
Browse files Browse the repository at this point in the history
  • Loading branch information
loivsen authored May 28, 2024
1 parent d3a7c76 commit c2f993b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/uui-card-media/lib/uui-card-media.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ export class UUICardMediaElement extends UUICardElement {
font-size: var(--uui-type-small-size);
box-sizing: border-box;
padding: var(--uui-size-2) var(--uui-size-4);
text-align: left;
word-break: break-word;
}
:host([disabled]) #open-part {
Expand Down
13 changes: 13 additions & 0 deletions packages/uui-input-lock/lib/UUIInputLockEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { UUIEvent } from '@umbraco-ui/uui-base/lib/events';
import { UUIInputLockElement } from './uui-input-lock.element';

export class UUIInputLockEvent extends UUIEvent<{}, UUIInputLockElement> {
public static readonly LOCK_CHANGE: string = 'lock-change';

constructor(evName: string, eventInit: any | null = {}) {
super(evName, {
...{ bubbles: true },
...eventInit,
});
}
}
3 changes: 3 additions & 0 deletions packages/uui-input-lock/lib/uui-input-lock.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
iconUnlock,
} from '@umbraco-ui/uui-icon-registry-essential/lib/svgs';
import { property } from 'lit/decorators.js';
import { UUIInputLockEvent } from './UUIInputLockEvent';

/**
* @element uui-input-lock
Expand Down Expand Up @@ -37,6 +38,8 @@ export class UUIInputLockElement extends UUIInputElement {

_onLockToggle() {
this.readonly = this.locked = !this.locked;
this.pristine = false;
this.dispatchEvent(new UUIInputLockEvent(UUIInputLockEvent.LOCK_CHANGE));
}

renderIcon() {
Expand Down
20 changes: 19 additions & 1 deletion packages/uui-input-lock/lib/uui-input-lock.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { expect, fixture, html } from '@open-wc/testing';
import { expect, fixture, html, oneEvent } from '@open-wc/testing';
import { UUIInputElement } from '@umbraco-ui/uui-input/lib';
import '@umbraco-ui/uui-icon/lib';
import '@umbraco-ui/uui-button/lib';

import { UUIInputLockElement } from './uui-input-lock.element';
import { UUIInputLockEvent } from './UUIInputLockEvent';

describe('UUIInputLockElement', () => {
let element: UUIInputLockElement;
Expand Down Expand Up @@ -45,4 +46,21 @@ describe('UUIInputLockElement', () => {
await toggle.click();
await expect(element.readonly).to.be.true;
});

it('emits lock change event', async () => {
const listener = oneEvent(element, UUIInputLockEvent.LOCK_CHANGE, false);

const toggle = element.shadowRoot?.querySelector(
'#lock',
) as HTMLButtonElement;
await toggle.click();

const event = await listener;

expect(event).to.exist;
expect(event.type).to.equal(UUIInputLockEvent.LOCK_CHANGE);
expect(event.bubbles).to.be.true;
expect(event.composed).to.be.false;
expect(event!.target).to.equal(element);
});
});

0 comments on commit c2f993b

Please sign in to comment.