Skip to content

Commit 64702ee

Browse files
author
Jan Miksovsky
committed
Update components in preparation for 0.6.3 release
1 parent edb2b79 commit 64702ee

2 files changed

Lines changed: 97 additions & 20 deletions

File tree

basic-list-box.html

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@
6565
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
6666
}
6767

68+
:host {
69+
--basic-list-box: {
70+
border: 1px solid gray;
71+
box-sizing: border-box;
72+
cursor: default;
73+
};
74+
}
75+
6876
[target="child"] {
6977
display: -webkit-flex;
7078
display: flex;
@@ -81,13 +89,15 @@
8189

8290
/* Generic appearance */
8391
:host([generic=""]) {
84-
border: 1px solid gray;
85-
box-sizing: border-box;
86-
cursor: default;
92+
@apply(--basic-list-box);
8793
}
8894

8995
:host([generic=""]) #itemsContainer ::content > * {
96+
cursor: default;
9097
padding: 0.25em;
98+
-webkit-user-select: none;
99+
-moz-user-select: none;
100+
user-select: none;
91101
}
92102
</style>
93103

@@ -116,6 +126,10 @@
116126
Basic.SelectionScroll
117127
],
118128

129+
// attributeChanged: function(name, type) {
130+
// console.log("changed", name);
131+
// },
132+
119133
behaviors: [
120134
Basic.Aspect,
121135
Basic.Generic
@@ -145,9 +159,34 @@
145159
},
146160

147161
properties: {
162+
163+
selectedIndex: {
164+
type: Number
165+
},
166+
167+
selectedItem: {
168+
type: Object
169+
},
170+
148171
target: {
149172
value: 'shadow'
150173
}
174+
175+
},
176+
177+
/**
178+
* Ensures the selected item is visible. This normally happens by default.
179+
* However, if the list box is hidden when the selection is changed, the
180+
* auto-scrolling feature won't apply. In that situation, call this method
181+
* after the list box becomes visible.
182+
*
183+
* @method scrollSelectedItemIntoView
184+
*/
185+
scrollSelectedItemIntoView: function() {
186+
var item = this.collective.selectedItem;
187+
if (item) {
188+
this.collective.scrollItemIntoView(item);
189+
}
151190
},
152191

153192
/**
@@ -158,7 +197,10 @@
158197
* @type Number
159198
*/
160199
get selectedIndex() {
161-
return this.collective.selectedIndex;
200+
// See note at basic-item-selection's selectedIndex getter.
201+
if (this._readied) {
202+
return this.collective.selectedIndex;
203+
}
162204
},
163205
set selectedIndex(index) {
164206
this.collective.selectedIndex = index;
@@ -211,6 +253,41 @@
211253
*/
212254
selectPrevious: function() {
213255
return this.collective.selectPrevious();
256+
},
257+
258+
/**
259+
* The text content of the selected item.
260+
*
261+
* Setting this to text not found in any list item will set selectedItem to
262+
* null.
263+
*
264+
* @property value
265+
* @type String
266+
*/
267+
get value() {
268+
return this.selectedItem == null || this.selectedItem.textContent == null ?
269+
'' :
270+
this.selectedItem.textContent;
271+
},
272+
set value(text) {
273+
274+
var currentIndex = this.selectedIndex;
275+
var newIndex = -1; // Assume we won't find the text.
276+
277+
// Find the item with the indicated text.
278+
var items = this.items;
279+
for (i = 0, length = items.length; i < length; i++) {
280+
if (items[i].textContent === text) {
281+
newIndex = i;
282+
break;
283+
}
284+
}
285+
286+
if (newIndex !== currentIndex) {
287+
this.selectedIndex = newIndex;
288+
var event = new CustomEvent('value-changed');
289+
this.dispatchEvent(event);
290+
}
214291
}
215292

216293
});

bower.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
{
22
"name": "basic-list-box",
33
"description": "A single-selection list box that supports selection highlighting (using the system highlight color) and keyboard navigation.",
4-
"version": "0.6.2",
4+
"version": "0.6.3",
55
"license": "MIT",
66
"main": "basic-list-box.html",
77
"dependencies": {
8-
"basic-accessible-list": "basic-web-components/basic-accessible-list#0.6.2",
9-
"basic-aspect": "basic-web-components/basic-aspect#0.6.2",
10-
"basic-children-content": "basic-web-components/basic-children-content#0.6.2",
11-
"basic-content-items": "basic-web-components/basic-content-items#0.6.2",
12-
"basic-direction-selection": "basic-web-components/basic-direction-selection#0.6.2",
13-
"basic-item-selection": "basic-web-components/basic-item-selection#0.6.2",
14-
"basic-keyboard": "basic-web-components/basic-keyboard#0.6.2",
15-
"basic-keyboard-direction": "basic-web-components/basic-keyboard-direction#0.6.2",
16-
"basic-keyboard-paging": "basic-web-components/basic-keyboard-paging#0.6.2",
17-
"basic-keyboard-prefix-selection": "basic-web-components/basic-keyboard-prefix-selection#0.6.2",
18-
"basic-selection-highlight": "basic-web-components/basic-selection-highlight#0.6.2",
19-
"basic-selection-scroll": "basic-web-components/basic-selection-scroll#0.6.2",
20-
"basic-tap-selection": "basic-web-components/basic-tap-selection#0.6.2",
21-
"basic-shared": "basic-web-components/basic-shared#0.6.2",
8+
"basic-accessible-list": "basic-web-components/basic-accessible-list#0.6.3",
9+
"basic-aspect": "basic-web-components/basic-aspect#0.6.3",
10+
"basic-children-content": "basic-web-components/basic-children-content#0.6.3",
11+
"basic-content-items": "basic-web-components/basic-content-items#0.6.3",
12+
"basic-direction-selection": "basic-web-components/basic-direction-selection#0.6.3",
13+
"basic-item-selection": "basic-web-components/basic-item-selection#0.6.3",
14+
"basic-keyboard": "basic-web-components/basic-keyboard#0.6.3",
15+
"basic-keyboard-direction": "basic-web-components/basic-keyboard-direction#0.6.3",
16+
"basic-keyboard-paging": "basic-web-components/basic-keyboard-paging#0.6.3",
17+
"basic-keyboard-prefix-selection": "basic-web-components/basic-keyboard-prefix-selection#0.6.3",
18+
"basic-selection-highlight": "basic-web-components/basic-selection-highlight#0.6.3",
19+
"basic-selection-scroll": "basic-web-components/basic-selection-scroll#0.6.3",
20+
"basic-tap-selection": "basic-web-components/basic-tap-selection#0.6.3",
21+
"basic-shared": "basic-web-components/basic-shared#0.6.3",
2222
"polymer": "Polymer/polymer#^1.1"
2323
},
2424
"devDependencies": {
25-
"basic-framed-content": "basic-web-components/basic-framed-content#0.6.2",
25+
"basic-framed-content": "basic-web-components/basic-framed-content#0.6.3",
2626
"web-component-tester": "*"
2727
},
2828
"keywords": [

0 commit comments

Comments
 (0)