|
1 | 1 | import { expect } from '@vaadin/chai-plugins'; |
2 | 2 | import { sendKeys } from '@vaadin/test-runner-commands'; |
3 | | -import { fixtureSync, nextRender, nextUpdate } from '@vaadin/testing-helpers'; |
| 3 | +import { fixtureSync, nextRender, nextResize, nextUpdate } from '@vaadin/testing-helpers'; |
4 | 4 | import sinon from 'sinon'; |
| 5 | +import './menu-bar-test-styles.js'; |
5 | 6 | import '../src/vaadin-menu-bar.js'; |
6 | 7 |
|
7 | 8 | describe('keyboard navigation', () => { |
@@ -138,6 +139,82 @@ describe('keyboard navigation', () => { |
138 | 139 | expect(buttons[3].hasAttribute('focused')).to.be.true; |
139 | 140 | }); |
140 | 141 | }); |
| 142 | + |
| 143 | + describe('overflow', () => { |
| 144 | + beforeEach(async () => { |
| 145 | + menu.items = [{ text: 'Item Foo' }, { text: 'Item Bar' }]; |
| 146 | + await nextRender(); |
| 147 | + buttons = menu._buttons; |
| 148 | + }); |
| 149 | + |
| 150 | + it('should move focus back to the overflow button on Shift + Tab after Tab', async () => { |
| 151 | + // Hide all buttons except overflow |
| 152 | + menu.style.width = '100px'; |
| 153 | + await nextResize(menu); |
| 154 | + |
| 155 | + firstGlobalFocusable.focus(); |
| 156 | + await sendKeys({ press: 'Tab' }); |
| 157 | + expect(document.activeElement).to.equal(menu._overflow); |
| 158 | + |
| 159 | + await sendKeys({ press: 'Tab' }); |
| 160 | + expect(document.activeElement).to.equal(lastGlobalFocusable); |
| 161 | + |
| 162 | + await sendKeys({ press: 'Shift+Tab' }); |
| 163 | + expect(document.activeElement).to.equal(menu._overflow); |
| 164 | + }); |
| 165 | + |
| 166 | + it('should move focus back to the overflow button on Tab after Shift + Tab', async () => { |
| 167 | + // Show 1 button + overflow |
| 168 | + menu.style.width = '120px'; |
| 169 | + await nextResize(menu); |
| 170 | + |
| 171 | + lastGlobalFocusable.focus(); |
| 172 | + await sendKeys({ press: 'Shift+Tab' }); |
| 173 | + expect(document.activeElement).to.equal(menu._overflow); |
| 174 | + |
| 175 | + await sendKeys({ press: 'Shift+Tab' }); |
| 176 | + expect(document.activeElement).to.equal(firstGlobalFocusable); |
| 177 | + |
| 178 | + await sendKeys({ press: 'Tab' }); |
| 179 | + expect(document.activeElement).to.equal(menu._overflow); |
| 180 | + }); |
| 181 | + |
| 182 | + it('should move focus back to the overflow button on Tab after button is hidden', async () => { |
| 183 | + lastGlobalFocusable.focus(); |
| 184 | + await sendKeys({ press: 'Shift+Tab' }); |
| 185 | + expect(document.activeElement).to.equal(buttons[1]); |
| 186 | + |
| 187 | + await sendKeys({ press: 'Shift+Tab' }); |
| 188 | + expect(document.activeElement).to.equal(firstGlobalFocusable); |
| 189 | + |
| 190 | + // Hide all buttons except overflow |
| 191 | + menu.style.width = '100px'; |
| 192 | + await nextResize(menu); |
| 193 | + |
| 194 | + await sendKeys({ press: 'Tab' }); |
| 195 | + expect(document.activeElement).to.equal(menu._overflow); |
| 196 | + }); |
| 197 | + |
| 198 | + it('should not skip buttons on Tab after overflow becomes hidden', async () => { |
| 199 | + // Hide all buttons except overflow |
| 200 | + menu.style.width = '100px'; |
| 201 | + await nextResize(menu); |
| 202 | + |
| 203 | + firstGlobalFocusable.focus(); |
| 204 | + await sendKeys({ press: 'Tab' }); |
| 205 | + expect(document.activeElement).to.equal(menu._overflow); |
| 206 | + |
| 207 | + await sendKeys({ press: 'Tab' }); |
| 208 | + expect(document.activeElement).to.equal(lastGlobalFocusable); |
| 209 | + |
| 210 | + // Show all buttons and hide overflow |
| 211 | + menu.style.width = '100%'; |
| 212 | + await nextResize(menu); |
| 213 | + |
| 214 | + await sendKeys({ press: 'Shift+Tab' }); |
| 215 | + expect(document.activeElement).to.equal(buttons[1]); |
| 216 | + }); |
| 217 | + }); |
141 | 218 | }); |
142 | 219 |
|
143 | 220 | describe('tab navigation mode', () => { |
|
0 commit comments