Skip to content

Commit 71a114f

Browse files
Merge pull request #23 from Travelopia/fix/multi-select-search
Multi Select: Fix search issue
2 parents cb129ff + ff265cd commit 71a114f

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@travelopia/web-components",
3-
"version": "0.5.7",
3+
"version": "0.5.8",
44
"description": "Accessible web components for the modern web",
55
"files": [
66
"dist"

src/multi-select/tp-multi-select-option.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@ export class TPMultiSelectOptionElement extends HTMLElement {
2828

2929
if ( 'yes' !== this.getAttribute( 'selected' ) ) {
3030
multiSelect?.select( value );
31-
multiSelect?.dispatchEvent( new CustomEvent( 'select', { bubbles: true } ) );
31+
multiSelect?.dispatchEvent( new CustomEvent( 'select', {
32+
bubbles: true,
33+
detail: { value },
34+
} ) );
3235
} else {
3336
multiSelect?.unSelect( value );
34-
multiSelect?.dispatchEvent( new CustomEvent( 'unselect', { bubbles: true } ) );
37+
multiSelect?.dispatchEvent( new CustomEvent( 'unselect', {
38+
bubbles: true,
39+
detail: { value },
40+
} ) );
3541
}
3642
multiSelect?.dispatchEvent( new CustomEvent( 'change', { bubbles: true } ) );
3743
}

src/multi-select/tp-multi-select-search.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class TPMultiSelectSearchElement extends HTMLElement {
6767
let matchedOptionCount = 0;
6868
// Hide and show options based on search.
6969
options.forEach( ( option: TPMultiSelectOptionElement ): void => {
70-
if ( option.getAttribute( 'value' )?.match( new RegExp( `.*${ search.value }.*` ) ) ) {
70+
if ( option.getAttribute( 'label' )?.toLowerCase().match( new RegExp( `.*${ search.value.replace( /\s/g, '.*' ) }.*` ) ) ) {
7171
option.removeAttribute( 'hidden' );
7272
matchedOptionCount++;
7373
} else {

0 commit comments

Comments
 (0)