Skip to content

Commit b2f76a7

Browse files
committed
add hidelabel attr to abstract-select, support in input-mode-select
rename AbstractSelectLitElement to AbstractSelectElement
1 parent 93c46a3 commit b2f76a7

4 files changed

Lines changed: 17 additions & 26 deletions

File tree

example.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<body>
3434

3535
<acc-side-panel label="Components">
36-
<acc-group label="Tracking Group" hidelabel>
37-
<acc-input-mode-select contentselector="#main-content">
36+
<acc-group label="Tracking">
37+
<acc-input-mode-select contentselector="#main-content" hidelabel>
3838
<acc-mouse-input amplification="10" label="Custom Mouse/Keyboard"></acc-mouse-input>
3939
<acc-pose-input amplification="2" smoothing="0.5"></acc-pose-input>
4040
</acc-input-mode-select>

src/components/abstract-select.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { UIProperties } from './abstract-ui';
12
// Copyright 2018 Google LLC
23
//
34
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,6 +24,10 @@ import { property } from "./decorators";
2324
const { FlattenedNodesObserver } = require('@polymer/polymer/lib/utils/flattened-nodes-observer.js');
2425

2526

27+
export interface SelectProperties extends UIProperties {
28+
hideLabel: boolean;
29+
}
30+
2631
export interface SelectableElement extends Element {
2732
selected:boolean;
2833
value:string;
@@ -40,7 +45,7 @@ export const isSelectableElement = (el:any): el is SelectableElement =>
4045
* AbstractSelectLitElement is an Abstract class and therefore should always be extended
4146
* This class manages the [selected] attribute state of all children added into its slot
4247
*/
43-
export class AbstractSelectLitElement extends AbstractUIElement {
48+
export class AbstractSelectElement extends AbstractUIElement {
4449

4550
/**
4651
* hide the label visually, only provide to aria

src/components/input-mode-select.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import { backgroundColor, bodyFontFamily, labelColor, labelStyleChunk } from './styles';
1616
import { html } from '@polymer/lit-element';
17-
import { SelectableElement, AbstractSelectLitElement } from './abstract-select';
17+
import { SelectableElement, AbstractSelectElement, SelectProperties } from './abstract-select';
1818
import { property } from './decorators';
1919

2020

@@ -37,33 +37,22 @@ interface UIElements {
3737
* Creates a UI element for selecting an appropriate input method,
3838
* bundles proper initialization, event bubbling, access to calibration
3939
* and messaging.
40-
* @extends AbstractSelectLitElement
40+
* @extends AbstractSelectElement
4141
*/
42-
export class InputModeSelectElement extends AbstractSelectLitElement {
42+
export class InputModeSelectElement extends AbstractSelectElement {
4343

4444
/**
4545
* provide a selector for the content element the input is applied to
4646
*/
4747
@property({ type: String })
4848
public contentSelector:string = 'body'; //'acc-content';
4949

50-
51-
@property({ type: String})
52-
public label:string = '';
53-
5450
constructor() {
5551
super();
5652
this._nodeChildSelector = '*';
53+
this.label = this.label || 'Tracking';
5754
}
5855

59-
// focus() {
60-
// super.focus();
61-
// const select = this.shadowRoot.querySelector('select');
62-
// if(select) {
63-
// select.focus();
64-
// }
65-
// }
66-
6756

6857
set contentElement(element: HTMLElement | null) {
6958
this.items.forEach(item => {
@@ -131,7 +120,7 @@ export class InputModeSelectElement extends AbstractSelectLitElement {
131120
super._addNode(node);
132121
}
133122

134-
_render({label}:UIElements){
123+
_render({label, hideLabel}: SelectProperties){
135124
const sI = this.selectedIndex;
136125
const hasControls = this.selected && this.selected.hasControls;
137126

@@ -213,9 +202,9 @@ export class InputModeSelectElement extends AbstractSelectLitElement {
213202
}
214203
215204
</style>
216-
<label for="select">Tracking</label>
205+
${hideLabel ? '' : html`<label for="select">${label}</label>`}
217206
<div class="select-style">
218-
<select class="accessibility-selector" on-input="${onSelectInput}" id="select">
207+
<select class="accessibility-selector" on-input="${onSelectInput}" id="select" aria-label$="${label}">
219208
${this.items.map((node,i)=>{
220209
const isSelected = i === sI;
221210
return html`<option value="${node.inputType}" selected="${isSelected}">${node.label}</option>`;

src/components/select.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import autobind from 'autobind-decorator';
1616
import { backgroundColor, bodyFontFamily, labelColor } from './styles';
17-
import { SelectableElement, AbstractSelectLitElement, isOptgroupElement } from './abstract-select';
17+
import { SelectableElement, AbstractSelectElement, isOptgroupElement } from './abstract-select';
1818
import { OptgroupElement } from './optgroup';
1919

2020
import { html } from '@polymer/lit-element';
@@ -42,10 +42,7 @@ const toOptionTemplate = (node: OptionItem) =>
4242

4343

4444

45-
export class SelectElement extends AbstractSelectLitElement {
46-
47-
48-
protected labelHtml:any;
45+
export class SelectElement extends AbstractSelectElement {
4946

5047

5148
get items(): OptionItem[] {

0 commit comments

Comments
 (0)