Skip to content

Commit 87f419b

Browse files
authored
Merge pull request #180 from umbraco/bugfix/missing-uui-key-registration
2 parents bda771a + 21ea2fe commit 87f419b

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
12
import { css, html, LitElement } from 'lit';
2-
import { queryAssignedNodes } from 'lit/decorators.js';
33

44
/**
55
* A visual representation of a key on you keyboard. use inside `<uui-keyboard-shortcut></uui-keyboard-shortcut>`
66
* @element uui-key
77
* @slot - for the key name. Anything you put in here will be lowercase.
88
*/
9+
@defineElement('uui-key')
910
export class UUIKeyElement extends LitElement {
1011
static styles = [
1112
css`
@@ -19,23 +20,18 @@ export class UUIKeyElement extends LitElement {
1920
padding: 5px 7px;
2021
box-sizing: border-box;
2122
user-select: none;
23+
text-transform: lowercase;
2224
}
2325
`,
2426
];
2527

26-
@queryAssignedNodes()
27-
private slotNodes!: NodeList;
28-
29-
private _changeCase() {
30-
if (this.slotNodes !== null) {
31-
this.slotNodes.forEach(node => {
32-
if (node.nodeName === '#text' && node.nodeValue)
33-
node.nodeValue = node.nodeValue?.toLowerCase();
34-
});
35-
}
28+
render() {
29+
return html`<slot></slot>`;
3630
}
31+
}
3732

38-
render() {
39-
return html`<slot @slotchange=${this._changeCase}></slot>`;
33+
declare global {
34+
interface HTMLElementTagNameMap {
35+
'uui-key': UUIKeyElement;
4036
}
4137
}

packages/uui-keyboard-shortcut/lib/uui-keyboard-shortcut.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import { html, fixture, expect } from '@open-wc/testing';
22
import { UUIKeyboardShortcutElement } from './uui-keyboard-shortcut.element';
3+
import { UUIKeyElement } from './uui-key.element';
34
import '.';
45

56
describe('UUIKey', () => {
6-
let element: UUIKeyboardShortcutElement;
7+
let element: UUIKeyElement;
78
beforeEach(async () => {
8-
element = await fixture(html`<uui-key>z</uui-key> `);
9+
element = await fixture(html`<uui-key>ESC</uui-key> `);
10+
});
11+
12+
it('is defined', () => {
13+
expect(element).to.be.instanceOf(UUIKeyElement);
914
});
1015

1116
it('passes the a11y audit', async () => {
1217
await expect(element).shadowDom.to.be.accessible();
1318
});
19+
20+
it('lowercase text content of element', async () => {
21+
expect(element.innerText).to.equal('esc');
22+
});
1423
});
1524

1625
describe('UUIKeyboardShortcut', () => {
@@ -29,6 +38,10 @@ describe('UUIKeyboardShortcut', () => {
2938
`);
3039
});
3140

41+
it('is defined', () => {
42+
expect(element).to.be.instanceOf(UUIKeyboardShortcutElement);
43+
});
44+
3245
it('passes the a11y audit', async () => {
3346
await expect(element).shadowDom.to.be.accessible();
3447
});

0 commit comments

Comments
 (0)