Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(AdaptiveTabs): add ReactNode support for hint #239

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/components/AdaptiveTabs/AdaptiveTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
const b = block('adaptive-tabs');
const TAB_CLASS_NAME = b('tab');
const getSortObjectKeysByValuesFunc =
(objectToSort: Record<string, any>) => (a: string, b: string) => {

Check warning on line 24 in src/components/AdaptiveTabs/AdaptiveTabs.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type

Check warning on line 24 in src/components/AdaptiveTabs/AdaptiveTabs.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

'b' is already declared in the upper scope on line 21 column 7
if (objectToSort[a] > objectToSort[b]) {
return 1;
}
Expand Down Expand Up @@ -56,7 +56,7 @@
export interface TabProps {
id: string;
title?: string | React.ReactNode;
hint?: string;
hint?: string | React.ReactNode;
active?: boolean;
disabled?: boolean;
onClick?: (id: string, event: React.MouseEvent) => void;
Expand All @@ -71,7 +71,7 @@
// eslint-disable-next-line jsx-a11y/click-events-have-key-events
<div
className={b('tab', {active, disabled})}
title={stringTitle}
title={typeof stringTitle === 'string' ? stringTitle : undefined}
onClick={disabled ? undefined : this.onClick}
>
{title}
Expand Down Expand Up @@ -185,7 +185,7 @@
private tabsRootNode = React.createRef<HTMLDivElement>();
private tabsListNode = React.createRef<HTMLDivElement>();

get activeTab() {

Check warning on line 188 in src/components/AdaptiveTabs/AdaptiveTabs.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

getter functions should be placed after render
const {activeTab, items, allowNotSelected} = this.props;
if (activeTab) {
return activeTab;
Expand Down Expand Up @@ -213,7 +213,7 @@

this.breakpoints = Object.keys(props.breakpointsConfig)
.map(Number)
.sort((a, b) => a - b);

Check warning on line 216 in src/components/AdaptiveTabs/AdaptiveTabs.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

'b' is already declared in the upper scope on line 21 column 7

/* save the object, where the keys are the "name" of the current container width, the values are the maximum width of the tab for
the corresponding container width (in percent of the container width) */
Expand All @@ -227,7 +227,7 @@
breakpointName = LARGE_CONTAINER_WIDTH_NAME;
}

accum[breakpointName] = props.breakpointsConfig[currentBreakpointWidth] || 100;

Check warning on line 230 in src/components/AdaptiveTabs/AdaptiveTabs.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Assignment to property of function parameter 'accum'

return accum;
},
Expand All @@ -246,9 +246,9 @@
this.setState({currentContainerWidthName: this.getCurrentContainerWidthName()});

if (this.tabsRootNode.current.clientWidth > this.breakpoints[0]) {
if ((document as any).fonts) {

Check warning on line 249 in src/components/AdaptiveTabs/AdaptiveTabs.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
(document as any).fonts.ready.then(this.initialCollectDimensions);

Check warning on line 250 in src/components/AdaptiveTabs/AdaptiveTabs.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
} else if ((document as any).readyState === READY_STATE_COMPLETE) {

Check warning on line 251 in src/components/AdaptiveTabs/AdaptiveTabs.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
setTimeout(this.initialCollectDimensions, 0);
} else {
window.addEventListener('load', this.initialCollectDimensions);
Expand Down Expand Up @@ -769,14 +769,14 @@
const {items} = this.props;
const activeTab = items.find((item) => item.id === this.activeTab);
const tab = activeTab ?? items[0];
const hint = tab.hint ?? ((typeof tab.title === 'string' && tab.title) || tab.id);
const hint = tab.hint ?? (tab.title || tab.id);

return this.renderSwitcher({...switcherProps, text: hint, active: Boolean(activeTab)});
};

renderSwitcher = (
switcherProps: RenderControlProps & {
text: string;
text: string | React.ReactNode;
active?: boolean;
},
) => {
Expand Down
Loading