Tabs Component does not update selectedIndex if previously selected-Tab is removed from children

Open
#2,798 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

  • #3279 by @mangeshraut712 — closed without merging

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, react
Domain
frontend

Research direction

Locate the Tabs component and its getSelectedIndex method, then reproduce the two-tab case where the selected second tab is removed. Confirm that the remaining tab becomes selected when the selected index is outside the available range.

Written by the indexing model from the issue text.

Description

stale tabs

Hi,

I have a Tabs component with 2 tabs. Here we dynamically show and hide tabs.

  1. User selects the 2nd tab => selectedIndex = 1
  2. Because of certain user action, We hide the 2nd selected tab. total tabs-count = 1
  3. Issue:- After this action 1st tab is not automatically selected
  4. Root Cause:- selectedIndex is still 1, which is out of boundary as tabs-count =1 .

Ideally end user expects the current available tab should be selected.

`getSelectedIndex() {
if( Number.isInteger(this.props.selectedIndex))
return this.props.selectedIndex;

        // Suggested fix, reset to 0 or update to defaultSelectionIndex
         return this.state.selectionIndex> this.getTabsCount() - 1 ? 0: this.state.selectionIndex;

`
Thanks,
Praveen

Dominant language
JavaScript
Stars
994
Forks
444
Avg merge
3d 23h
Merged PRs (30d)
44

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from salesforce/design-system-react

All issues in salesforce/design-system-react

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.