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

The selected property issue on TabContainer #1953

Closed
mrmabo opened this issue Jul 14, 2020 · 3 comments · Fixed by #1974
Closed

The selected property issue on TabContainer #1953

mrmabo opened this issue Jul 14, 2020 · 3 comments · Fixed by #1974
Assignees

Comments

@mrmabo
Copy link

mrmabo commented Jul 14, 2020

Describe the bug
If the selected tab rendered due to the API response, the selected property on this tab cannot be invoked properly.

To reproduce
Steps to reproduce the behavior:

  1. Set the selected attribute on Prerequisites
  2. Make an API call to render this tab.

Expected behavior
Add boolean value on the selected attribute so that we can set the Prerequisites tab selected is true and other tabs selected is false after component renders.

Screenshots
Prerequisites tab base on the API response to render, and add the selected attribute on this tab. The content of Prerequisites will display underneath the content of Course Details.
image

Context

  • UI5 Web Components version : 0.21.7
  • OS/Platform: Windows and Mac
@ilhan007
Copy link
Member

Hi @mrmabo

can you describe the steps by adding your code, the markup and the API calls you mentioned.

If you create a codesandbox example, it would be great!

BR,
ilhan

@ilhan007 ilhan007 self-assigned this Jul 15, 2020
@mrmabo
Copy link
Author

mrmabo commented Jul 21, 2020

Hi @ilhan007

Here is what I tried, but it doesn't work

<ui5-tabcontainer class="full-width" collapsed fixed show-overflow>
        <ui5-tab text="Home" selected="false"></ui5-tab>
        <ui5-tab text="What's new" selected="true"></ui5-tab>
        <ui5-tab text="Who are we"></ui5-tab>
        <ui5-tab text="About"></ui5-tab>
        <ui5-tab text="Contacts"></ui5-tab>
</ui5-tabcontainer>

By adding a selected attribute, always selects the tab irrespective of the attribute value true or false.

@fifoosid
Copy link
Contributor

fifoosid commented Jul 22, 2020

Hi @mrmabo

This is one way how you can achieve the expected behaviour in React:

function App () {

  const [selectedTab, setSelectedTab] = useState(0);

  setTimeout(() => {
    setSelectedTab(selectedTab => 2)
  }, 3000)

  return (
    <ui5-busyindicator style={{width: 100 + '%'}} active={selectedTab === 0 || undefined}>
      <ui5-tabcontainer collapsed fixed show-overflow>
        <ui5-tab text="Home" selected={selectedTab === 1 || undefined} />
        <ui5-tab text="What's new" selected={selectedTab === 2 || undefined} />
        <ui5-tab text="Who are we" selected={selectedTab === 3 || undefined} />
        <ui5-tab text="About" selected={selectedTab === 4 || undefined} />
        <ui5-tab text="Contacts" selected={selectedTab === 5 || undefined} />
      </ui5-tabcontainer>
    </ui5-busyindicator>
  );
}

Let me explain the code above:

  1. We initialise the selecetedTab as 0(no tab is selected)
  2. We fake an API call via the setTimeout
  3. selected={selectedTab === 1 || undefined} toggles the selected property on each tab
  4. You can notice that we are using the same syntax for the active attribute of the ui5-busyindicator(which is boolean as well): active={selectedTab === 0 || undefined}.

Note: The behaviour of setting the first tab as selected if no tab is initially selected from our side will be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants