|
32 | 32 | describe('items', () => {
|
33 | 33 | let rootMenu, subMenu, target;
|
34 | 34 |
|
| 35 | + const createComponent = (text) => { |
| 36 | + const item = document.createElement('vaadin-context-menu-item'); |
| 37 | + item.textContent = text; |
| 38 | + return item; |
| 39 | + }; |
| 40 | + |
35 | 41 | const menuComponents = (menu = rootMenu) => {
|
36 | 42 | return Array.from(menu.$.overlay.content.firstElementChild.children);
|
37 | 43 | };
|
|
84 | 90 | ]},
|
85 | 91 | ]
|
86 | 92 | },
|
87 |
| - {text: 'foo-1'} |
| 93 | + {text: 'foo-1'}, |
| 94 | + { |
| 95 | + text: 'foo-2', |
| 96 | + children: [ |
| 97 | + {component: createComponent('foo-2-0')}, |
| 98 | + {component: createComponent('foo-2-1')}, |
| 99 | + {component: createComponent('foo-2-2')} |
| 100 | + ] |
| 101 | + } |
88 | 102 | ];
|
89 | 103 | open();
|
90 | 104 | flush(() => {
|
|
396 | 410 | expect(spy).to.be.calledOnce;
|
397 | 411 | });
|
398 | 412 |
|
| 413 | + it('should focus first item after re-opening when using components', async() => { |
| 414 | + subMenu.close(); |
| 415 | + rootMenu.$.overlay.focus(); |
| 416 | + |
| 417 | + const rootItem = getMenuItems(rootMenu)[2]; |
| 418 | + |
| 419 | + // Open the sub-menu with item components |
| 420 | + open(rootItem); |
| 421 | + await nextRender(); |
| 422 | + const subMenu2 = getSubMenu(rootMenu); |
| 423 | + const items = getMenuItems(subMenu2); |
| 424 | + |
| 425 | + // Arrow Down to focus next item |
| 426 | + items[0].focus(); |
| 427 | + fire(items[0], 'keydown', {}, {keyCode: 40, key: 'ArrowDown'}); |
| 428 | + expect(items[1].hasAttribute('focus-ring')).to.be.true; |
| 429 | + |
| 430 | + // Arrow Left to close the sub-menu |
| 431 | + fire(items[1], 'keydown', {}, {keyCode: 37, key: 'ArrowLeft'}); |
| 432 | + await nextRender(); |
| 433 | + expect(rootItem.hasAttribute('focus-ring')).to.be.true; |
| 434 | + |
| 435 | + // Re-open sub-menu and check focus |
| 436 | + open(rootItem); |
| 437 | + await nextRender(); |
| 438 | + expect(items[0].hasAttribute('focus-ring')).to.be.true; |
| 439 | + }); |
| 440 | + |
399 | 441 | // elementFromPoint doesn't work properly with shadydom on ios 10.3
|
400 | 442 | if (!window.ShadyDOM) {
|
401 | 443 | it('should have modeless sub menus', () => {
|
|
0 commit comments