primeng icon indicating copy to clipboard operation
primeng copied to clipboard

p-tabview-panels displays panel which is not selected

Open flawesomesoft opened this issue 4 years ago • 3 comments

Describe the bug

Trying to implement a TabView with dynamic TabPanels.

According to the official documentation in this case the "selected" property of each TabPanel has to be handled manually.

The "activeIndex" property of the TabView doesn't seem to work in this case. So I set the activeIndex manually at the "OnChange()" event of the TabView

The dynamic tabView should support adding and closing tabs.

For some reason when closing the selected tab the tabView will also display the first tab in addition to the active tab.

The first tab is visually selected but the activeIndex is set to another tab. The browser source code shows the selected property of the first tab is set to false

Environment

Refer to stackblitz example

Reproducer

https://stackblitz.com/edit/github-kfg65h-u7z1qy?file=README.md

Angular version

11.0.4

PrimeNG version

14.0.0

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

12.11.1

Browser(s)

Tested on Chrome, Mozilla, Edge

Steps to reproduce the behavior

  1. Open Stackblitz example
  2. Close the active Tab (Tab#5)
  3. The TabView will display the content of the panel with the activeIndex (Tab#6) plus additionally the first panel
  4. Inspecting the source code of the browser => navigate to <div>class="p-tabview-panels"</div> => p-tabPanel for Tab#1 has ng-reflect-selected=false => p-tabPanel for Tab#6 has ng-reflect-selected=true

Expected behavior

Only the panel which is selected should be displayed

flawesomesoft avatar Sep 07 '22 08:09 flawesomesoft

Hi,

You need to bind activeIndex to the tabView to use it. Also, you're binding the "selected" twice with different conditions, maybe this was the problem. Here is a refactored version of your example https://stackblitz.com/edit/github-kfg65h-hzpahw?file=src%2Fapp%2Fapp.component.ts,src%2Fapp%2Fapp.component.html

cetincakiroglu avatar Sep 07 '22 13:09 cetincakiroglu

@cetincakiroglu you are right i was binding "selected" twice. Yet, the removal did not change anything of the strange behaviour (stackblitz updated).

Your example unfortunatly don't work as expected. If you close the currently active tab (e.g. Tab#5) the tabView simply selects the very first tab automatically. I couldn't find the reason for that behaviour. In onTabClose() there is no handling for this case so i was assuming the activeIndex just stays the same which would select the next tab automatically.

And this would be the desired handling for any tabView. E.g. take a look at Chrome-Tabs. If you close the selected tab, the next tab is selected (it will not just select the first tab in the tabView...)

I've noticed you completely removed the "selected" property from the tabPanel. But this is how it's described at the documentation:

Dynamic Tabs

p-tabPanel components can be generated dynamically using ngFor, note that in this case due to an Angular issue selected property must be enabled manually.

<p-tabView>
    <p-tabPanel [header]="item.header" *ngFor="let item of items; let i = index" [selected]="i == 0">
        {{item.content}}
    </p-tabPanel>
</p-tabView>

There is no binding for activeIndex at the TabView. And seemingly "selected" has to be enabled manually due to technical issues.

Properties of TabView

activeIndex | number | null | Index of the active tab to change selected tab programmatically.

Properties of TabPanel

selected | boolean | false | Defines if tab is active.

I don't see the reason why you have to deal with activeIndex of tabView when you are already setting the "selected" property of the tabPanel manually.

And it also seems like they don't work in combination (tried to implement in the stackblitz)

flawesomesoft avatar Sep 08 '22 06:09 flawesomesoft

Created new issue #11919 ....

flawesomesoft avatar Sep 12 '22 09:09 flawesomesoft