| OLD | NEW |
| (Empty) | |
| 1 var items = [ |
| 2 { |
| 3 title: "first", |
| 4 index: 0 |
| 5 }, |
| 6 { |
| 7 title: "second", |
| 8 index: 1 |
| 9 }, |
| 10 { |
| 11 title: "third", |
| 12 index: 2 |
| 13 }, |
| 14 { |
| 15 title: "fourth", |
| 16 index: 3 |
| 17 }, |
| 18 { |
| 19 title: "disabled 4.5", |
| 20 disabled: true, |
| 21 index: 4 |
| 22 }, |
| 23 { |
| 24 title: "fifth", |
| 25 index: 5 |
| 26 }, |
| 27 { |
| 28 title: "sixth", |
| 29 index: 6 |
| 30 }, |
| 31 { |
| 32 title: "seventh", |
| 33 index: 7 |
| 34 }, |
| 35 { |
| 36 title: "eighth", |
| 37 index: 8 |
| 38 } |
| 39 ]; |
| 40 |
| 41 class Delegate { |
| 42 titleFor(item) { |
| 43 return item.title; |
| 44 } |
| 45 |
| 46 renderElementForItem(element, item) { |
| 47 element.textContent = this.titleFor(item); |
| 48 } |
| 49 |
| 50 isItemSelectable(item) { |
| 51 return !item.disabled; |
| 52 } |
| 53 |
| 54 itemSelected(item) { |
| 55 if (item !== null) |
| 56 TestRunner.addResult("Item selected: " + this.titleFor(item)); |
| 57 } |
| 58 |
| 59 itemHighlighted(item) { |
| 60 if (item !== null) |
| 61 TestRunner.addResult("Item highlighted: " + this.titleFor(item)); |
| 62 } |
| 63 }; |
| 64 |
| 65 function pressKey(key) { |
| 66 var element = document.deepActiveElement(); |
| 67 if (!element) |
| 68 return; |
| 69 TestRunner.addResult(key); |
| 70 element.dispatchEvent(TestRunner.createKeyEvent(key)); |
| 71 } |
| 72 var model = new UI.ListModel(); |
| 73 var dropDown = new UI.SoftDropDown(model, new Delegate()); |
| 74 for (var i = items.length - 1; i >= 0; i--) |
| 75 model.insertItemWithComparator(items[i], (a, b) => a.index - b.index); |
| 76 |
| 77 UI.inspectorView.element.appendChild(dropDown.element); |
| 78 dropDown.selectItem(items[5]); |
| 79 TestRunner.addResult("Showing drop down"); |
| 80 dropDown.element.dispatchEvent(new Event("mousedown")); |
| 81 pressKey('ArrowDown'); |
| 82 pressKey('ArrowDown'); |
| 83 pressKey('ArrowDown'); |
| 84 pressKey('ArrowUp'); |
| 85 pressKey('ArrowUp'); |
| 86 pressKey('ArrowUp'); |
| 87 pressKey('ArrowDown'); |
| 88 pressKey('ArrowDown'); |
| 89 pressKey('f'); |
| 90 pressKey('f'); |
| 91 pressKey('t'); |
| 92 TestRunner.completeTest(); |
| OLD | NEW |