Skip to content

Commit 7aaae37

Browse files
committed
feat(formField): add label by attribute
adds a label by attribute if there are no existing labels in the field.
1 parent 0143c93 commit 7aaae37

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/form/ux-field.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ import { StyleEngine } from '../styles/style-engine';
44
import { Themable } from '../styles/themable';
55
import { processDesignAttributes } from '../designs/design-attributes';
66

7-
@inject(ViewResources, StyleEngine)
7+
@inject(Element, ViewResources, StyleEngine)
88
@customElement('ux-field')
99
@processAttributes(processDesignAttributes)
1010

1111
export class UxField implements Themable {
1212
@bindable public theme = null;
13+
@bindable public label: string;
1314

1415
public view: View;
1516

16-
constructor(public resources: ViewResources, private styleEngine: StyleEngine) { }
17+
constructor(private element: Element, public resources: ViewResources, private styleEngine: StyleEngine) { }
1718

1819
public created(_: any, myView: View) {
1920
this.view = myView;
@@ -23,6 +24,13 @@ export class UxField implements Themable {
2324
if (this.theme) {
2425
this.styleEngine.applyTheme(this, this.theme);
2526
}
27+
28+
if (this.label && !this.element.closest('label')) {
29+
const newLabel = document.createElement('label');
30+
newLabel.textContent = this.label;
31+
32+
this.element.insertBefore(newLabel, this.element.firstChild);
33+
}
2634
}
2735

2836
// public attached() { }

0 commit comments

Comments
 (0)