Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Multi-Select Cross Browser Pill Remove #50

Merged
merged 3 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@travelopia/web-components",
"version": "0.5.19",
"version": "0.5.21",
"description": "Accessible web components for the modern web",
"files": [
"dist"
Expand Down
2 changes: 1 addition & 1 deletion src/multi-select/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<tp-multi-select-field>
<tp-multi-select-pills></tp-multi-select-pills>
<tp-multi-select-search>
<input placeholder="Select...">
<input type="text" placeholder="Select...">
</tp-multi-select-search>
</tp-multi-select-field>
<tp-multi-select-options>
Expand Down
15 changes: 3 additions & 12 deletions src/multi-select/tp-multi-select-pill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,12 @@ export class TPMultiSelectPillElement extends HTMLElement {
/**
* Handle button click.
*
* @param {any} e Click event.
* @param {Event} e Click event.
*/
handleButtonClick( e: any | null ): void {
handleButtonClick( e: Event | null ): void {
e?.preventDefault();
e?.stopPropagation();

/**
* If the event is has a pointerType, which means it's a mouse event or touch event
* Only then we remove pill.
* This will ensure, it will not get fired when a enter button is pressed.
* We do this so that it does not remove the pills when enter button is pressed.
*/
if ( e?.pointerType ) {
this.removePill();
}
this.removePill();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/multi-select/tp-multi-select-pills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class TPMultiSelectPillsElement extends HTMLElement {
newPill.setAttribute( 'value', pillValue );
newPill.innerHTML = `
<span>${ multiSelectOption.getAttribute( 'label' ) ?? '' }</span>
<button>x</button>
<button type="button">x</button>
`;
this.appendChild( newPill );
} );
Expand Down
3 changes: 3 additions & 0 deletions src/multi-select/tp-multi-select-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class TPMultiSelectSearchElement extends HTMLElement {
}

switch ( e.key ) {
case 'Enter':
e.preventDefault(); // Prevent inadvertent form submits.
break;
case 'ArrowDown':
multiSelect.setAttribute( 'open', 'yes' );
break;
Expand Down
Loading