components icon indicating copy to clipboard operation
components copied to clipboard

Click-event not fired from button in mat-tab #11642

Open Hypenate opened this issue 7 years ago • 8 comments

Bug, enhancement request, or proposal:

Bug (or maybe an enhancement)

CodePen and steps to reproduce the issue:

Detailed Reproduction Steps:

I tried creating a tab that I can close by a button:

<ng-container *ngFor="let tab of tabs; let index = index">
      <mat-tab>
        <ng-template mat-tab-label>
          <div class="container-fluid" style="padding: 0;margin-left: 20px;">
            <div class="row">
              <div class="col" style="margin-left: 20px;">{{tab.displayName}}</div>
              <div class="col-auto" style="padding-right: 0;">
                <button style="color:black" mat-icon-button (click)="closeTab(1)">
                  <fa-icon icon="times" size="lg"></fa-icon>
                </button>
              </div>
            </div>
          </div>
        </ng-template>
        <span [ngSwitch]="tab.type">
          <div *ngSwitchCase="0" style="height: calc(100% - 30px);">
            <CSI-grid [dataSource]=" tab.dataSource" [columns]="tab.columns">
            </CSI-grid>
          </div>
          <div *ngSwitchCase="1" style="height: calc(100% - 8px);">
            <dx-dashboard></dx-dashboard>
          </div>
          <div *ngSwitchDefault>
            {{tab.type}} - This is default, should never be hit
          </div>
        </span>
      </mat-tab>
    </ng-container>

What is the expected behavior?

If I click on the tab, the tab is shown (works) If I click on the button inside the tab, the click event is thrown (doesn't work)

What is the current behavior?

If you click the button, the tab is selected but the click-event on the button is never fired.

What is the use-case or motivation for changing an existing behavior?

The animated is displayed correct as you can see in the screenshot.

Which versions of AngularJS, Material, OS, and browsers are affected?

  • AngularJS: 7.3.2
  • AngularJS Material: 7.3.2
  • OS: /
  • Browsers: All

Is there anything else we should know? Stack Traces, Screenshots, etc.

image

Hypenate avatar Feb 20 '19 07:02 Hypenate

Referencing https://github.com/angular/material/issues/11642

Hypenate avatar Feb 20 '19 07:02 Hypenate

@Hypenate I tried to recreate a simplified version of your use case, you can find the StackBlitz here. In the above example, clicking on the button does fire the proper event handler and the tab is closed. I'm not using any other libraries other than material and I don't have any fancy CSS, so the issue you're experiencing (not firing the button event) could perhaps be coming from one of those?

ViktorSlavov avatar Feb 20 '19 09:02 ViktorSlavov

@ViktorSlavov Thanks for the guidance!

@Hypenate I was having the same issue and for me, as pointed by Viktor, some other CSS was not allowing click event on the active tab.

rsrgithub avatar Apr 05 '19 18:04 rsrgithub

@Hypenate can you share a reproduction?

jelbourn avatar May 12 '19 15:05 jelbourn

I am experiencing this behavior as well. In my case, click events inside the mat-tab element are not being registered until it has focus (or focus is removed from somewhere else).

In my case, the mat-tab-group is located inside a modal dialog, with this structure:

            <mat-tab-group>
                <mat-tab label="Items">
                    <div class="selection-list">
                        <mat-action-list dense>
                            <ng-container *ngIf="context$ | async as ctx">
                                <button mat-list-item *ngFor="let s of ctx.GetItems()" (click)="Insert(s)">{{s.name}}</button>
                            </ng-container>
                        </mat-action-list>
                    </div>
                </mat-tab>
                <mat-tab label="Functions">
                    <div class="selection-list">
                        <mat-action-list dense>
                            <button mat-list-item>Example 1</button>
                            <button mat-list-item>Example 2</button>
                        </mat-action-list>
                    </div>
                </mat-tab>
            </mat-tab-group>
            <mat-form-field class="w-100">
                <mat-label>Filter</mat-label>
                <input matInput type="text" value="" />
            </mat-form-field>

What I am seeing is if the input below the tabs has focus, or the tab headers themselves, when the button inside the tab is clicked, the initial click is not registered but subsequent ones are. If I click somewhere on the modal itself which can not receive focus, and then click the button, the click is also registered.

I have tried inspecting the elements on the browser and I can't see any CSS that is blocking the button.

I'm running Angular 8.1.0 and Material 8.0.2

marlon-tucker avatar Jul 09 '19 12:07 marlon-tucker

Hello, everyone! I have the same issue with button inside of modal window. Button doesn't fires click event

bsayat avatar Apr 20 '20 07:04 bsayat

We haven't been able to reproduce this issue. Feel free to open a new issue if you are able to provide a reproduction via StackBlitz.

(this is a canned response)

jelbourn avatar May 26 '20 22:05 jelbourn

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.