ionic-team / ionic-team/ionic-framework

bug: Programmatically switching tabs in basic mode doesn't work

Đang mở
#30,037 1 bình luận 1 reaction 0 người được giao Xem trên GitHub
triage
Ngôn ngữ chính
TypeScript
Star
52.7k
Fork
13.3k
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
51

Mô tả

### Prerequisites

- [X] I have read the [Contributing Guidelines](https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#creating-an-issue).
- [X] I agree to follow the [Code of Conduct](https://ionicframework.com/code-of-conduct).
- [X] I have searched for [existing issues](https://github.com/ionic-team/ionic-framework/issues) that already report this problem, without success.

### Ionic Framework Version

v8.x

### Current Behavior

I'm using `` in basic mode (i.e. without a router).

I wanted to switch tabs programmatically, using the IonTabsContext, like this
```
function TabSwitcher() {
const tabContext = useContext(IonTabsContext);

const switchToTab = (tab: string) => {
tabContext.selectTab(tab); // Programmatically switch to the specified tab
};

return (


switchToTab('radio')}>
Go to Radio tab


);
}
```

Then I used this component in one tab, wanting it to switch to another tab:
```





Home content





```

But when I click the button to switch tabs, nothing happens.

When I debugged the code, the context is there, it has the correct structure, the function `selectTab(tab)` exists, it just doesn't change the tab,

### Expected Behavior

Calling `tabContext.selectTab(tab)` should change the active tab to the tab `Radio`.

### Steps to Reproduce

1. Go to https://ionicframework.com/docs/api/tabs#basic-usage and fork the example code.
2. Create the TabSwitcher component and add it to the first tab.
3. Observe that clicking the TabSwitcher button doesn't switch tabs to the second tab.

### Code Reproduction URL

https://stackblitz.com/~/github.com/jansoltis/ionic-tabs-switch-issue?file=src/main.tsx

### Ionic Info

Ionic:

Ionic CLI : 7.2.0 (C:\Users\admin\AppData\Roaming\nvm\v20.11.1\node_modules\@ionic\cli)
Ionic Framework : @ionic/react 8.4.0

Capacitor:

Capacitor CLI : 6.1.2
@capacitor/android : 6.1.2
@capacitor/core : 6.1.2
@capacitor/ios : 6.1.2

Utility:

cordova-res : 0.15.4
native-run : 2.0.1

System:

NodeJS : v20.11.1 (C:\Program Files\nodejs\node.exe)
npm : 10.2.4
OS : Windows 10

### Additional Information

_No response_

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.