Skip to content

Commit 9c7139a

Browse files
committed
2 parents dffd670 + 1991f86 commit 9c7139a

File tree

9 files changed

+56
-32
lines changed

9 files changed

+56
-32
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
All notable changes to this project will be documented in this file.
55
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
66

7+
## [4.3.1](https://github.com/ghiscoding/multiple-select-vanilla/compare/v4.3.0...v4.3.1) (2025-06-14)
8+
9+
### Bug Fixes
10+
11+
* when `closeOnTab` w/OK button, it should take 2 Tabs to close ([#388](https://github.com/ghiscoding/multiple-select-vanilla/issues/388)) ([9742825](https://github.com/ghiscoding/multiple-select-vanilla/commit/97428259c3098253a2cf47dbd8b2c4b7e3259975)) - by @ghiscoding
12+
713
## [4.3.0](https://github.com/ghiscoding/multiple-select-vanilla/compare/v4.2.2...v4.3.0) (2025-06-14)
814

915
### Features

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "node_modules/@lerna-lite/cli/schemas/lerna-schema.json",
3-
"version": "4.3.0",
3+
"version": "4.3.1",
44
"npmClient": "pnpm",
55
"loglevel": "verbose",
66
"command": {

packages/multiple-select-vanilla/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
All notable changes to this project will be documented in this file.
55
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
66

7+
## [4.3.1](https://github.com/ghiscoding/multiple-select-vanilla/compare/v4.3.0...v4.3.1) (2025-06-14)
8+
9+
### Bug Fixes
10+
11+
* when `closeOnTab` w/OK button, it should take 2 Tabs to close ([#388](https://github.com/ghiscoding/multiple-select-vanilla/issues/388)) ([9742825](https://github.com/ghiscoding/multiple-select-vanilla/commit/97428259c3098253a2cf47dbd8b2c4b7e3259975)) - by @ghiscoding
12+
713
## [4.3.0](https://github.com/ghiscoding/multiple-select-vanilla/compare/v4.2.2...v4.3.0) (2025-06-14)
814

915
### Features

packages/multiple-select-vanilla/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "multiple-select-vanilla",
33
"description": "This lib allows you to select multiple elements with checkboxes",
4-
"version": "4.3.0",
4+
"version": "4.3.1",
55
"keywords": [
66
"checkboxes",
77
"multiple-select",

packages/multiple-select-vanilla/src/MultipleSelectInstance.ts

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,6 @@ export class MultipleSelectInstance {
278278
'body-click',
279279
);
280280
}
281-
282-
// listen to Tab and call `onBlur` when that happens
283-
this._bindEventService.bind(this.dropElm, 'keyup', ((e: KeyboardEvent) => {
284-
if (e.code === 'Tab') {
285-
this.options.onBlur(e);
286-
if (this.options.closeOnTab) {
287-
this.close('blur');
288-
}
289-
}
290-
}) as EventListener);
291281
}
292282

293283
protected initData() {
@@ -1125,22 +1115,26 @@ export class MultipleSelectInstance {
11251115
break;
11261116
}
11271117
case 'Tab': {
1128-
// when clicking Tab, we'll focus on OK button when available
1129-
// or with Shift+Tab we'll either focus first option when coming
1130-
// from OK button or close drop if we're already in the lsit
1118+
// when clicking "Tab" and we're using a multiple select and we're not focusing on "OK" button yet, we'll do focus to it.
1119+
// otherwise we'll call the `onBlur` callback and/or `closeOnTab` is enabled we'll do that too.
11311120
e.preventDefault();
1132-
if (e.shiftKey) {
1133-
if (document.activeElement === this.okButtonElm) {
1134-
this.focusSelectAllOrList();
1135-
this.highlightCurrentOption();
1136-
} else {
1137-
this.close('key.shift+tab');
1138-
this.choiceElm.focus();
1139-
}
1140-
} else {
1121+
1122+
// when using multiple select with "OK" button
1123+
const isMultiple = !this.options.single && this.options.showOkButton;
1124+
if (isMultiple && e.shiftKey && document.activeElement === this.okButtonElm) {
1125+
this.focusSelectAllOrList();
1126+
this.highlightCurrentOption();
1127+
this.filterParentElm?.querySelector('input')?.focus();
1128+
} else if (isMultiple && !e.shiftKey && document.activeElement !== this.okButtonElm) {
11411129
this.changeCurrentOptionHighlight();
11421130
this.okButtonElm?.focus();
1131+
} else {
1132+
this.options.onBlur(e);
1133+
if (this.options.isOpen && this.options.closeOnTab) {
1134+
this.close('blur');
1135+
}
11431136
}
1137+
11441138
break;
11451139
}
11461140
}

packages/multiple-select-vanilla/src/models/multipleSelectOption.interface.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ export interface MultipleSelectOption extends MultipleSelectLocale {
7373
/** The class prefix of select. */
7474
classPrefix?: string;
7575

76-
/** Should we close the drop when Tab key is pressed. */
76+
/**
77+
* Should we close the drop when Tab key is pressed.
78+
* Side note: when using a multiple select with the "OK" button enabled,
79+
* it will require 2 Tabs (1. focus on "OK", 2. close drop)
80+
*/
7781
closeOnTab?: boolean;
7882

7983
/** HTML container to use for the drop menu, e.g. 'body' */

playwright/e2e/options25.spec.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test.describe('Options 25 - Show OK Button', () => {
2828
});
2929

3030
test('Tab and Shift+Tab to switch from OK button to List', async ({ page }) => {
31-
// 1st select
31+
// 1st Select
3232
await page.goto('#/options25');
3333
await page.locator('[data-test=select1].ms-parent').click();
3434
await page.getByRole('option', { name: 'April' }).click();
@@ -39,14 +39,26 @@ test.describe('Options 25 - Show OK Button', () => {
3939
await expect(page.locator('div[data-test=select1] .ms-ok-button')).toBeFocused();
4040
await page.keyboard.press('Shift+Tab');
4141
await expect(page.locator('div[data-test=select1] .ms-select-all input')).toBeFocused();
42-
await page.keyboard.press('Shift+Tab');
42+
await page.keyboard.press('Tab');
43+
await page.keyboard.press('Enter');
4344
await expect(page.locator('div[data-test=select1] .ms-drop')).toBeHidden();
4445

45-
// last select Shift+Tab will close drop
46+
// 3rd Select
47+
await page.locator('[data-test=select3].ms-parent').click();
48+
await page.locator('div:nth-child(2) > label > .icon-checkbox-container').click();
49+
await page.keyboard.press('Tab');
50+
await expect(page.locator('div[data-test=select3] .ms-ok-button')).toBeFocused();
51+
await page.keyboard.press('Shift+Tab');
52+
await expect(page.locator('div[data-test=select3] .ms-search input')).toBeFocused();
53+
await page.keyboard.press('Tab');
54+
await page.keyboard.press('Enter');
55+
await expect(page.locator('div[data-test=select3] .ms-drop')).toBeHidden();
56+
57+
// 4th Select Enter key will close drop
4658
await page.locator('[data-test=select4].ms-parent').click();
4759
await page.keyboard.press('ArrowDown');
4860
await page.keyboard.press('ArrowDown');
49-
await page.keyboard.press('Shift+Tab');
61+
await page.keyboard.press('Enter');
5062
await expect(page.locator('div[data-test=select4] .ms-drop')).toBeHidden();
5163
});
5264
});

playwright/e2e/options34.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { test, expect } from '@playwright/test';
1+
import { expect, test } from '@playwright/test';
22

33
test.describe('Options 34 - Show Search Clear button', () => {
44
test('filtering on all type of select & clear search input', async ({ page }) => {

playwright/e2e/options43.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ test.describe('Options 43 - Close on Tab', () => {
3737
// 5th Select
3838
await page.locator('div[data-test=data1] .ms-choice').click();
3939
await expect(page.locator('div[data-test=data1] .ms-drop')).toBeVisible();
40-
await page.keyboard.press('Tab');
40+
await page.keyboard.press('Tab'); // 1st Tab will focus on "OK" button
41+
await expect(page.locator('div[data-test=data1] .ms-drop')).toBeVisible();
42+
await expect(page.locator('div[data-test=data1] .ms-ok-button')).toBeFocused();
43+
await page.keyboard.press('Tab'); // 2nd Tab will close the drop
4144
await expect(page.locator('div[data-test=data1] .ms-drop')).not.toBeVisible();
42-
// });
4345
});
4446
});

0 commit comments

Comments
 (0)