Skip to content

Commit

Permalink
Merge pull request #2400 from kirbydesign/bug/2388-badge-click-remove…
Browse files Browse the repository at this point in the history
…s-focus

Avoid removing focus from Segmented Control on embedded badge click
  • Loading branch information
RasmusKjeldgaard authored Aug 4, 2022
2 parents 32c47d2 + f9ab6bb commit 78f8cad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[value]="value?.id"
[scrollable]="disableChangeOnSwipe"
(ionChange)="onSegmentSelect($event.detail.value)"
(click)="preventWrapperClick($event)"
(click)="preventOutsideClick($event)"
>
<div *ngFor="let item of items" class="segment-btn-wrapper">
<ion-segment-button [value]="item.id">{{ item.text }}</ion-segment-button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ export enum SegmentedControlMode {
export class SegmentedControlComponent {
constructor(private iconRegistryService: IconRegistryService) {}

preventWrapperClick(event: Event) {
/**
* Ensure that the click actually did originate from within the segment-button.
* We do not want to react to clicks on e.g. segment-btn-wrapper or badge.
*/
preventOutsideClick(event: TouchEvent) {
if (event.target instanceof HTMLElement) {
if (event.target.classList.contains('segment-btn-wrapper')) {
const targetIsInSegmentBtn = !!event.target.closest('ion-segment-button');
if (!targetIsInSegmentBtn) {
event.stopImmediatePropagation();
}
}
Expand Down

0 comments on commit 78f8cad

Please sign in to comment.