Skip to content

Commit 4e65e00

Browse files
CopilotmfranzkenmergetmichaelmkrausCopilot
authored
fix(DBTabs): arrows not appearing on window resize (#4812)
* Initial plan * Fix DBTabs arrows not appearing on window resize Co-authored-by: mfranzke <787658+mfranzke@users.noreply.github.com> * chore: refactor window resize listener by moving it to own file * Update .changeset/fix-dbtabs-arrows-on-resize.md Co-authored-by: Maximilian Franzke <787658+mfranzke@users.noreply.github.com> * chore: refactor window-resize-listener.ts with resizeObserver * Update packages/components/src/components/tabs/tabs.lite.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update packages/components/src/components/tabs/tabs.lite.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: revert index.html for tabs --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Maximilian Franzke <787658+mfranzke@users.noreply.github.com> Co-authored-by: Nicolas Merget <nicolas.merget@deutschebahn.com> Co-authored-by: Michael Kraus <michael.m.kraus@deutschebahn.com> Co-authored-by: Nicolas Merget <104347736+nmerget@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 0233048 commit 4e65e00

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@db-ux/core-components": patch
3+
"@db-ux/ngx-core-components": patch
4+
"@db-ux/react-core-components": patch
5+
"@db-ux/v-core-components": patch
6+
"@db-ux/wc-core-components": patch
7+
---
8+
9+
fix(DBTabs): ensure navigation arrows appear correctly on window resize
10+
This update resolves an issue where navigation arrows in DBTabs would not appear or update correctly when the window was resized. The component now properly responds to resize events, ensuring arrows are always shown or hidden as needed.

packages/components/src/components/tabs/model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export type DBTabsDefaultState = {
8888
initTabList: () => void;
8989
initTabs: (init?: boolean) => void;
9090
handleChange: (event: InputEvent<HTMLElement>) => void;
91+
_resizeObserver?: ResizeObserver;
9192
};
9293

9394
export type DBTabsState = DBTabsDefaultState & GlobalState & InitializedState;

packages/components/src/components/tabs/tabs.lite.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
For,
33
onMount,
4+
onUnMount,
45
onUpdate,
56
Show,
67
useDefaultProps,
@@ -30,6 +31,7 @@ export default function DBTabs(props: DBTabsProps) {
3031
showScrollLeft: false,
3132
showScrollRight: false,
3233
scrollContainer: null,
34+
_resizeObserver: undefined,
3335
convertTabs(): DBSimpleTabProps[] {
3436
try {
3537
if (typeof props.tabs === 'string') {
@@ -80,6 +82,14 @@ export default function DBTabs(props: DBTabsProps) {
8082
container.addEventListener('scroll', () => {
8183
state.evaluateScrollButtons(container);
8284
});
85+
// Use ResizeObserver to re-evaluate scroll buttons because it provides more accurate, container-specific resize detection than global window resize events.
86+
if (!state._resizeObserver) {
87+
const observer = new ResizeObserver(() => {
88+
state.evaluateScrollButtons(container);
89+
});
90+
observer.observe(container);
91+
state._resizeObserver = observer;
92+
}
8393
}
8494
}
8595
}
@@ -186,6 +196,11 @@ export default function DBTabs(props: DBTabsProps) {
186196
});
187197
// jscpd:ignore-end
188198

199+
onUnMount(() => {
200+
state._resizeObserver?.disconnect();
201+
state._resizeObserver = undefined;
202+
});
203+
189204
onUpdate(() => {
190205
if (_ref && state.initialized) {
191206
state.initTabList();

0 commit comments

Comments
 (0)