Skip to content

Commit 74d4449

Browse files
Tabs, TabPanel: improve typing and fix all eslint errors (#29600)
1 parent 1f0ce71 commit 74d4449

File tree

5 files changed

+169
-131
lines changed

5 files changed

+169
-131
lines changed

packages/devextreme/js/__internal/ui/collection/collection_widget.base.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,11 +1344,12 @@ class CollectionWidget<
13441344
itemTemplate,
13451345
renderArgs: ItemRenderInfo<TItem>,
13461346
) {
1347+
const { itemData, container, index } = renderArgs;
13471348
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
13481349
return itemTemplate.render({
1349-
model: renderArgs.itemData,
1350-
container: renderArgs.container,
1351-
index: renderArgs.index,
1350+
model: itemData,
1351+
container,
1352+
index,
13521353
onRendered: this._onItemTemplateRendered(itemTemplate, renderArgs),
13531354
});
13541355
}

packages/devextreme/js/__internal/ui/collection/m_collection_widget.edit.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,6 @@ class CollectionWidget<
486486
config?: ActionConfig,
487487
): void {
488488
let itemSelectPromise = Deferred().resolve();
489-
490489
this._createAction((e) => {
491490
itemSelectPromise = this._itemSelectHandler(e.event) ?? itemSelectPromise;
492491
}, {
@@ -495,7 +494,6 @@ class CollectionWidget<
495494
itemElement: $(e.currentTarget),
496495
event: e,
497496
});
498-
// const parentItemClickHandler = super._itemClickHandler.bind(this);
499497
// eslint-disable-next-line @typescript-eslint/no-floating-promises
500498
itemSelectPromise.always(() => {
501499
super._itemClickHandler(e, args, config);
@@ -513,7 +511,6 @@ class CollectionWidget<
513511

514512
const $itemElement = e.currentTarget;
515513

516-
// @ts-expect-error ts-error
517514
if (this.isItemSelected($itemElement)) {
518515
this.unselectItem(e.currentTarget);
519516
} else {
@@ -822,8 +819,7 @@ class CollectionWidget<
822819
this._optionChangedAction?.({ name: optionName, fullName: optionName, value: optionValue });
823820
}
824821

825-
isItemSelected(itemElement: dxElementWrapper | number): boolean {
826-
// @ts-expect-error ts-error
822+
isItemSelected(itemElement: Element | number): boolean {
827823
return this._isItemSelected(this._editStrategy.getNormalizedIndex(itemElement));
828824
}
829825

packages/devextreme/js/__internal/ui/list/m_list.base.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { getHeight, getOuterHeight, setHeight } from '@js/core/utils/size';
2121
import { isDefined, isPlainObject } from '@js/core/utils/type';
2222
import { hasWindow } from '@js/core/utils/window';
2323
import Button from '@js/ui/button';
24-
import type { Properties } from '@js/ui/list';
24+
import type { Item, Properties } from '@js/ui/list';
2525
import ScrollView from '@js/ui/scroll_view';
2626
import { current, isMaterial, isMaterialBased } from '@js/ui/themes';
2727
import { render } from '@js/ui/widget/utils.ink_ripple';
@@ -70,7 +70,7 @@ export interface ListBaseProperties extends Properties<ListBase> {
7070

7171
showChevronExpr?: (data) => boolean | undefined;
7272

73-
badgeExpr?: (data) => boolean | undefined;
73+
badgeExpr?: (data) => string | undefined;
7474

7575
wrapItemText?: boolean;
7676

@@ -230,11 +230,11 @@ export class ListBase extends CollectionWidget<ListBaseProperties> {
230230
useInkRipple: false,
231231
wrapItemText: false,
232232
_swipeEnabled: true,
233-
234-
showChevronExpr(data) { return data ? data.showChevron : undefined; },
235-
badgeExpr(data) { return data ? data.badge : undefined; },
236-
237-
_onItemsRendered: () => {},
233+
showChevronExpr(data: Item): boolean | undefined {
234+
return data?.showChevron;
235+
},
236+
badgeExpr(data: Item): string | undefined { return data?.badge; },
237+
_onItemsRendered: (): void => {},
238238
};
239239
}
240240

@@ -243,15 +243,15 @@ export class ListBase extends CollectionWidget<ListBaseProperties> {
243243
// @ts-expect-error ts-error
244244
return super._defaultOptionsRules().concat(deviceDependentOptions(), [
245245
{
246-
device() {
246+
device(): boolean {
247247
return !supportUtils.nativeScrolling;
248248
},
249249
options: {
250250
useNativeScrolling: false,
251251
},
252252
},
253253
{
254-
device(device) {
254+
device(device): boolean {
255255
return !supportUtils.nativeScrolling && !devices.isSimulator() && devices.real().deviceType === 'desktop' && device.platform === 'generic';
256256
},
257257
options: {
@@ -261,23 +261,23 @@ export class ListBase extends CollectionWidget<ListBaseProperties> {
261261
},
262262
},
263263
{
264-
device() {
264+
device(): boolean {
265265
return devices.real().deviceType === 'desktop' && !devices.isSimulator();
266266
},
267267
options: {
268268
focusStateEnabled: true,
269269
},
270270
},
271271
{
272-
device() {
272+
device(): boolean {
273273
return isMaterial(themeName);
274274
},
275275
options: {
276276
useInkRipple: true,
277277
},
278278
},
279279
{
280-
device() {
280+
device(): boolean {
281281
return isMaterialBased(themeName);
282282
},
283283
options: {
@@ -290,7 +290,7 @@ export class ListBase extends CollectionWidget<ListBaseProperties> {
290290
]);
291291
}
292292

293-
_visibilityChanged(visible) {
293+
_visibilityChanged(visible: boolean): void {
294294
if (visible) {
295295
this._updateLoadingState(true);
296296
}

packages/devextreme/js/__internal/ui/tab_panel/m_tab_panel.ts

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {
2+
DefaultOptionsRule,
23
Orientation, Position, TabsIconPosition, TabsStyle,
34
} from '@js/common';
45
import registerComponent from '@js/core/component_registrator';
@@ -10,7 +11,8 @@ import $ from '@js/core/renderer';
1011
import { BindableTemplate } from '@js/core/templates/bindable_template';
1112
import { getImageContainer } from '@js/core/utils/icon';
1213
import { isDefined, isPlainObject } from '@js/core/utils/type';
13-
import type { Properties } from '@js/ui/tab_panel';
14+
import type { DxEvent } from '@js/events';
15+
import type { Item, Properties } from '@js/ui/tab_panel';
1416
import { current as currentTheme, isFluent, isMaterialBased } from '@js/ui/themes';
1517
import supportUtils from '@ts/core/utils/m_support';
1618
import type { OptionChanged } from '@ts/core/widget/types';
@@ -71,7 +73,7 @@ const STYLING_MODE: Record<TabsStyle, TabsStyle> = {
7173
export interface TabPanelProperties extends Properties {
7274
_tabsIndicatorPosition?: Position | null;
7375

74-
badgeExpr?: (data) => boolean | undefined;
76+
badgeExpr?: (data) => string | undefined;
7577

7678
focusedElement?: dxElementWrapper;
7779
}
@@ -111,26 +113,27 @@ class TabPanel extends MultiView<TabPanelProperties> {
111113
onTitleHold: null,
112114
// @ts-expect-error ts-error
113115
onTitleRendered: null,
114-
badgeExpr(data) { return data ? data.badge : undefined; },
115-
116+
badgeExpr(data: Item): string | undefined {
117+
return data?.badge;
118+
},
116119
_tabsIndicatorPosition: null,
117120
};
118121
}
119122

120-
_defaultOptionsRules() {
123+
_defaultOptionsRules(): DefaultOptionsRule<TabPanelProperties>[] {
121124
const themeName = currentTheme();
122125

123126
return super._defaultOptionsRules().concat([
124127
{
125-
device() {
128+
device(): boolean {
126129
return devices.real().deviceType === 'desktop' && !devices.isSimulator();
127130
},
128131
options: {
129132
focusStateEnabled: true,
130133
},
131134
},
132135
{
133-
device() {
136+
device(): boolean {
134137
return !supportUtils.touch;
135138
},
136139
options: {
@@ -144,15 +147,15 @@ class TabPanel extends MultiView<TabPanelProperties> {
144147
},
145148
},
146149
{
147-
device() {
150+
device(): boolean {
148151
return isFluent(themeName);
149152
},
150153
options: {
151154
stylingMode: STYLING_MODE.secondary,
152155
},
153156
},
154157
{
155-
device() {
158+
device(): boolean {
156159
return isMaterialBased(themeName);
157160
},
158161
options: {
@@ -169,22 +172,25 @@ class TabPanel extends MultiView<TabPanelProperties> {
169172
this._toggleTabPanelTabsPositionClass();
170173
}
171174

172-
_getElementAria() {
175+
// eslint-disable-next-line class-methods-use-this
176+
_getElementAria(): Record<string, string> {
173177
return { role: 'tabpanel' };
174178
}
175179

176-
_getItemAria() {
180+
// eslint-disable-next-line class-methods-use-this
181+
_getItemAria(): Record<string, string> {
177182
return { role: 'tabpanel' };
178183
}
179184

180-
_initMarkup() {
185+
_initMarkup(): void {
181186
super._initMarkup();
182187

183188
this._createTitleActions();
184189
this._renderLayout();
185190
}
186191

187-
_prepareTabsItemTemplate(data, $container) {
192+
// eslint-disable-next-line class-methods-use-this
193+
_prepareTabsItemTemplate(data: Item, $container: dxElementWrapper): void {
188194
const $iconElement = getImageContainer(data?.icon);
189195

190196
if ($iconElement) {
@@ -205,7 +211,7 @@ class TabPanel extends MultiView<TabPanelProperties> {
205211
}
206212
}
207213

208-
_initTemplates() {
214+
_initTemplates(): void {
209215
super._initTemplates();
210216

211217
this._templateManager.addDefaultTemplates({
@@ -273,11 +279,12 @@ class TabPanel extends MultiView<TabPanelProperties> {
273279
this.setAria('controls', id, $activeTab);
274280
}
275281

276-
_getTabsIndicatorPosition() {
282+
_getTabsIndicatorPosition(): Position {
277283
// eslint-disable-next-line @typescript-eslint/naming-convention
278284
const { _tabsIndicatorPosition, tabsPosition } = this.option();
279-
// @ts-expect-error ts-error
280-
return _tabsIndicatorPosition ?? TABS_INDICATOR_POSITION_BY_TABS_POSITION[tabsPosition];
285+
286+
return _tabsIndicatorPosition
287+
?? TABS_INDICATOR_POSITION_BY_TABS_POSITION[tabsPosition ?? TABS_POSITION.top];
281288
}
282289

283290
_tabConfig(): TabsProperties {
@@ -349,7 +356,7 @@ class TabPanel extends MultiView<TabPanelProperties> {
349356
itemTemplateProperty: 'tabTemplate',
350357
loopItemFocus: loop,
351358
selectionRequired: true,
352-
onOptionChanged: function (args) {
359+
onOptionChanged: (args): void => {
353360
if (args.name === 'focusedElement') {
354361
if (args.value) {
355362
const $value = $(args.value);
@@ -359,13 +366,13 @@ class TabPanel extends MultiView<TabPanelProperties> {
359366
this.option('focusedElement', args.value);
360367
}
361368
}
362-
}.bind(this),
363-
onFocusIn: function (args) { this._focusInHandler(args.event); }.bind(this),
364-
onFocusOut: function (args) {
369+
},
370+
onFocusIn: (args): void => { this._focusInHandler(args.event); },
371+
onFocusOut: (args): void => {
365372
if (!this._isFocusOutHandlerExecuting) {
366373
this._focusOutHandler(args.event);
367374
}
368-
}.bind(this),
375+
},
369376
orientation: this._getTabsOrientation(),
370377
iconPosition,
371378
stylingMode,
@@ -389,9 +396,9 @@ class TabPanel extends MultiView<TabPanelProperties> {
389396
}
390397

391398
_getTabPanelTabsPositionClass(): string {
392-
const position = this.option('tabsPosition');
399+
const { tabsPosition } = this.option();
393400

394-
switch (position) {
401+
switch (tabsPosition) {
395402
case TABS_POSITION.right:
396403
return TABPANEL_TABS_POSITION_CLASS.right;
397404
case TABS_POSITION.bottom:
@@ -421,15 +428,15 @@ class TabPanel extends MultiView<TabPanelProperties> {
421428
this._setTabsOption('orientation', orientation);
422429
}
423430

424-
_toggleWrapperFocusedClass(isFocused): void {
431+
_toggleWrapperFocusedClass(isFocused: boolean): void {
425432
this._toggleFocusClass(isFocused, this._$wrapper);
426433
}
427434

428-
_toggleDisabledFocusedClass(isFocused): void {
435+
_toggleDisabledFocusedClass(isFocused: boolean): void {
429436
this._focusTarget().toggleClass(DISABLED_FOCUSED_TAB_CLASS, isFocused);
430437
}
431438

432-
_updateFocusState(e, isFocused): void {
439+
_updateFocusState(e: DxEvent, isFocused: boolean): void {
433440
super._updateFocusState(e, isFocused);
434441

435442
const isTabsTarget = e.target === this._tabs._focusTarget().get(0);
@@ -454,32 +461,31 @@ class TabPanel extends MultiView<TabPanelProperties> {
454461
}
455462
}
456463

457-
_focusOutHandler(e): void {
464+
_focusOutHandler(e: DxEvent): void {
458465
this._isFocusOutHandlerExecuting = true;
459-
// @ts-expect-error ts-error
460-
super._focusOutHandler.apply(this, arguments);
466+
super._focusOutHandler(e);
461467

462468
this._tabs._focusOutHandler(e);
463469
this._isFocusOutHandlerExecuting = false;
464470
}
465471

466-
_setTabsOption(name, value): void {
472+
_setTabsOption(name: keyof TabsProperties, value: unknown): void {
467473
if (this._tabs) {
468474
this._tabs.option(name, value);
469475
}
470476
}
471477

472-
_postprocessSwipe({ swipedTabsIndex }): void {
473-
this._setTabsOption('selectedIndex', swipedTabsIndex);
478+
_postprocessSwipe(args: { swipedTabsIndex: number }): void {
479+
this._setTabsOption('selectedIndex', args.swipedTabsIndex);
474480
}
475481

476-
_visibilityChanged(visible): void {
482+
_visibilityChanged(visible: boolean): void {
477483
if (visible) {
478484
this._tabs._dimensionChanged();
479485
}
480486
}
481487

482-
registerKeyHandler(key, handler): void {
488+
registerKeyHandler(key: string, handler: (event?) => void): void {
483489
super.registerKeyHandler(key, handler);
484490

485491
if (this._tabs) {
@@ -520,8 +526,10 @@ class TabPanel extends MultiView<TabPanelProperties> {
520526
case 'selectedItem': {
521527
this._setTabsOption(fullName, value);
522528
super._optionChanged(args);
523-
// @ts-expect-error ts-error
524-
if (this.option('focusStateEnabled') === true) {
529+
530+
const { focusStateEnabled } = this.option();
531+
532+
if (focusStateEnabled === true) {
525533
const selectedIndex = this.option('selectedIndex');
526534
// @ts-expect-error ts-error
527535
const selectedTabContent = this._itemElements().eq(selectedIndex);

0 commit comments

Comments
 (0)