Skip to content

Commit 1e078da

Browse files
authored
refactor(ui5-tabcontainer): delete ITab interface (#8593)
- Removes `ITab` interface. TabContainer already works only with Tab and TabSeparator, therefore `ITab` only adds extra complexity. - Replaces `isInline`, `forcedMixedMode`, `forcedPosinset`, `forcedSetsize`, `isTopLevelTab`, `getElementInStrip` with 2 new methods: `receiveStripInfo(info)` and `receiveOverflowInfo(info)`. This way it is clear that those properties are not expected to be set by the Tab or TabSeparator, but are provided by the TabContainer in specific point in time - Makes `getTabInStripDomRef` return type match `UI5Element#getDomRef` BREAKING CHANGE: You can no longer import and implement the `ITab` interface. TabContainer is designed to work only with Tab and TabSeparator classes, so the interface was obsolete. Fixes: #8461
1 parent 14f4028 commit 1e078da

File tree

6 files changed

+205
-193
lines changed

6 files changed

+205
-193
lines changed

packages/main/src/Tab.ts

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import "@ui5/webcomponents-icons/dist/sys-enter-2.js";
2424
import SemanticColor from "./types/SemanticColor.js";
2525
import ListItemType from "./types/ListItemType.js";
2626
import TabContainer from "./TabContainer.js";
27-
import type { ITab } from "./TabContainer.js";
27+
import type TabSeparator from "./TabSeparator.js";
28+
import type { TabContainerStripInfo, TabContainerOverflowInfo } from "./TabContainer.js";
2829
import Icon from "./Icon.js";
2930
import Button from "./Button.js";
3031
import CustomListItem from "./CustomListItem.js";
@@ -47,6 +48,14 @@ const DESIGN_DESCRIPTIONS = {
4748
[SemanticColor.Critical]: TAB_ARIA_DESIGN_CRITICAL,
4849
};
4950

51+
interface TabInStrip extends HTMLElement {
52+
realTabReference: Tab;
53+
}
54+
55+
interface TabInOverflow extends CustomListItem {
56+
realTabReference: Tab;
57+
}
58+
5059
/**
5160
* @class
5261
* The `ui5-tab` represents a selectable item inside a `ui5-tabcontainer`.
@@ -55,7 +64,6 @@ const DESIGN_DESCRIPTIONS = {
5564
* @abstract
5665
* @constructor
5766
* @extends UI5Element
58-
* @implements {ITab}
5967
* @public
6068
*/
6169
@customElement({
@@ -70,7 +78,7 @@ const DESIGN_DESCRIPTIONS = {
7078
CustomListItem,
7179
],
7280
})
73-
class Tab extends UI5Element implements ITab, ITabbable {
81+
class Tab extends UI5Element implements ITabbable {
7482
/**
7583
* The text to be displayed for the item.
7684
* @default ""
@@ -143,11 +151,8 @@ class Tab extends UI5Element implements ITab, ITabbable {
143151
@property({ type: Boolean })
144152
forcedSelected!: boolean;
145153

146-
@property({ type: Object, defaultValue: null })
147-
realTabReference!: Tab;
148-
149154
@property({ type: Boolean })
150-
isTopLevelTab!: boolean;
155+
_isTopLevelTab!: boolean;
151156

152157
@property({ type: Object, defaultValue: null })
153158
_selectedTabReference!: Tab;
@@ -180,12 +185,15 @@ class Tab extends UI5Element implements ITab, ITabbable {
180185
slots: false,
181186
},
182187
})
183-
items!: Array<ITab>
188+
items!: Array<Tab | TabSeparator>
184189

185-
isInline?: boolean;
186-
forcedMixedMode?: boolean;
187-
getElementInStrip?: () => ITab | null;
190+
_isInline?: boolean;
191+
_forcedMixedMode?: boolean;
192+
_getElementInStrip?: () => HTMLElement | undefined;
188193
_individualSlot!: string;
194+
_forcedPosinset?: number;
195+
_forcedSetsize?: number;
196+
_forcedStyleInOverflow?: Record<string, any>;
189197

190198
static i18nBundle: I18nBundle;
191199

@@ -200,7 +208,7 @@ class Tab extends UI5Element implements ITab, ITabbable {
200208
get displayText() {
201209
let text = this.text;
202210

203-
if (this.isInline && this.additionalText) {
211+
if (this._isInline && this.additionalText) {
204212
text += ` (${this.additionalText})`;
205213
}
206214

@@ -224,15 +232,15 @@ class Tab extends UI5Element implements ITab, ITabbable {
224232
}
225233

226234
get requiresExpandButton() {
227-
return this.items.length > 0 && this.isTopLevelTab && this.hasOwnContent;
235+
return this.items.length > 0 && this._isTopLevelTab && this.hasOwnContent;
228236
}
229237

230238
get isSingleClickArea() {
231-
return this.items.length > 0 && this.isTopLevelTab && !this.hasOwnContent;
239+
return this.items.length > 0 && this._isTopLevelTab && !this.hasOwnContent;
232240
}
233241

234242
get isTwoClickArea() {
235-
return this.items.length > 0 && this.isTopLevelTab && this.hasOwnContent;
243+
return this.items.length > 0 && this._isTopLevelTab && this.hasOwnContent;
236244
}
237245

238246
get isOnSelectedTabPath(): boolean {
@@ -251,6 +259,21 @@ class Tab extends UI5Element implements ITab, ITabbable {
251259
return willShowContent(this.content);
252260
}
253261

262+
receiveStripInfo({
263+
getElementInStrip, posinset, setsize, isInline, isTopLevelTab, mixedMode,
264+
}: TabContainerStripInfo) {
265+
this._getElementInStrip = getElementInStrip;
266+
this._forcedPosinset = posinset;
267+
this._forcedSetsize = setsize;
268+
this._forcedMixedMode = mixedMode;
269+
this._isInline = isInline;
270+
this._isTopLevelTab = !!isTopLevelTab;
271+
}
272+
273+
receiveOverflowInfo({ style }: TabContainerOverflowInfo) {
274+
this._forcedStyleInOverflow = style;
275+
}
276+
254277
/**
255278
* Returns the DOM reference of the tab that is placed in the header.
256279
*
@@ -260,19 +283,19 @@ class Tab extends UI5Element implements ITab, ITabbable {
260283
* @public
261284
* @since 1.0.0-rc.16
262285
*/
263-
getTabInStripDomRef(): ITab | null {
264-
if (this.getElementInStrip) {
265-
return this.getElementInStrip();
286+
getTabInStripDomRef(): HTMLElement | undefined {
287+
if (this._getElementInStrip) {
288+
return this._getElementInStrip();
266289
}
267290

268-
return null;
291+
return undefined;
269292
}
270293

271294
getFocusDomRef() {
272295
let focusedDomRef = super.getFocusDomRef();
273296

274-
if (this.getElementInStrip && this.getElementInStrip()) {
275-
focusedDomRef = this.getElementInStrip()!;
297+
if (this._getElementInStrip && this._getElementInStrip()) {
298+
focusedDomRef = this._getElementInStrip()!;
276299
}
277300

278301
return focusedDomRef;
@@ -284,11 +307,11 @@ class Tab extends UI5Element implements ITab, ITabbable {
284307
}
285308

286309
get isMixedModeTab() {
287-
return !this.icon && this.forcedMixedMode;
310+
return !this.icon && this._forcedMixedMode;
288311
}
289312

290313
get isTextOnlyTab() {
291-
return !this.icon && !this.forcedMixedMode;
314+
return !this.icon && !this._forcedMixedMode;
292315
}
293316

294317
get isIconTab() {
@@ -345,23 +368,23 @@ class Tab extends UI5Element implements ITab, ITabbable {
345368
classes.push("ui5-tab-strip-item--disabled");
346369
}
347370

348-
if (this.isInline) {
371+
if (this._isInline) {
349372
classes.push("ui5-tab-strip-item--inline");
350373
}
351374

352375
if (this.additionalText) {
353376
classes.push("ui5-tab-strip-item--withAdditionalText");
354377
}
355378

356-
if (!this.icon && !this.forcedMixedMode) {
379+
if (!this.icon && !this._forcedMixedMode) {
357380
classes.push("ui5-tab-strip-item--textOnly");
358381
}
359382

360383
if (this.icon) {
361384
classes.push("ui5-tab-strip-item--withIcon");
362385
}
363386

364-
if (!this.icon && this.forcedMixedMode) {
387+
if (!this.icon && this._forcedMixedMode) {
365388
classes.push("ui5-tab-strip-item--mixedMode");
366389
}
367390

@@ -493,3 +516,7 @@ TabContainer.registerTabStyles(draggableElementStyles);
493516
TabContainer.registerTabStyles(overflowCss);
494517

495518
export default Tab;
519+
export type {
520+
TabInStrip,
521+
TabInOverflow,
522+
};

0 commit comments

Comments
 (0)