Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/custom-elements/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

<!-- ## Unreleased -->
## Unreleased

- Re implement the CustomElementRegistry interface ([#606](https://github.com/webcomponents/polyfills/pull/606))

## [1.6.0] - 2023-03-30

Expand Down
7 changes: 7 additions & 0 deletions packages/custom-elements/ts_src/CustomElementRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ export default class CustomElementRegistry {
return undefined;
}

getName(constructor: ElementConstructor): string | null {
const definition = this._constructorToDefinition.get(constructor);
return definition ? definition.localName : null;
}

whenDefined(localName: string): Promise<void> {
if (!Utilities.isValidCustomElementName(localName)) {
return Promise.reject(
Expand Down Expand Up @@ -363,4 +368,6 @@ CustomElementRegistry.prototype['polyfillDefineLazy'] =
CustomElementRegistry.prototype.polyfillDefineLazy;
CustomElementRegistry.prototype['polyfillWrapFlushCallback'] =
CustomElementRegistry.prototype.polyfillWrapFlushCallback;
CustomElementRegistry.prototype['getName'] =
CustomElementRegistry.prototype.getName;
/* eslint-enable no-self-assign */
17 changes: 17 additions & 0 deletions packages/tests/custom-elements/html/registry.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,23 @@
});
});

suite('getName', function () {
test('returns the local name for a defined custom element constructor', function () {
class XGetName extends HTMLElement {}
customElements.define('x-get-name', XGetName);

var name = customElements.getName(XGetName);
assert.equal(name, 'x-get-name');
});

test('returns null for an undefined custom element constructor', function () {
class XUndefinedElement extends HTMLElement {}

var name = customElements.getName(XUndefinedElement);
assert.isNull(name);
});
});

suite('whenDefined', function () {
test('resolves when a tag is defined', function () {
var promise = customElements
Expand Down
Loading