Skip to content

CTabs active not work properly #433

Closed
@nighttiger1990

Description

@nighttiger1990

In the below code. I change activeTab by clicking other button but Tabs not change

import React, { useState } from 'react';
import { CTab, CTabContent, CTabList, CTabPanel, CTabs } from '@coreui/react';

export const TabsControlledExample = () => {
  const [activeTab, setActiveTab] = useState('profile');
  const [tName, setTName] = useState('contact');
  const onClick = () => {
    console.log(tName);
    setActiveTab(tName);
  };

  return (
    <>
      <input defaultValue={tName} onChange={(e) => setTName(e.target.value)} />
      <button onClick={onClick}>click here</button>
      <CTabs activeItemKey={activeTab} onChange={setActiveTab}>
        <CTabList variant="tabs">
          <CTab itemKey="home">Home</CTab>
          <CTab itemKey="profile">Profile</CTab>
          <CTab itemKey="contact">Contact</CTab>
          <CTab disabled itemKey="disabled">
            Disabled
          </CTab>
        </CTabList>
        <CTabContent>
          <CTabPanel className="p-3" itemKey="home">
            Home tab content
          </CTabPanel>
          <CTabPanel className="p-3" itemKey="profile">
            Profile tab content
          </CTabPanel>
          <CTabPanel className="p-3" itemKey="contact">
            Contact tab content
          </CTabPanel>
          <CTabPanel className="p-3" itemKey="disabled">
            Disabled tab content
          </CTabPanel>
        </CTabContent>
      </CTabs>
    </>
  );
};

This is version of package

  "@coreui/coreui": "^5.3.2",
  "@coreui/react": "^5.5.0",

https://stackblitz.com/edit/react-b6qyor97?file=src%2FTabsControlledExample.jsx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions