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(core): can reset tooltip.renderTooltip in setOptions #2210

Merged
merged 10 commits into from
May 19, 2023
17 changes: 16 additions & 1 deletion packages/s2-core/__tests__/unit/sheet-type/pivot-sheet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,18 @@ describe('PivotSheet Tests', () => {
expect(s2.options.showSeriesNumber).toBeTruthy();
});

test('should init new tooltip', () => {
class CustomTooltip extends BaseTooltip {}
1wkk marked this conversation as resolved.
Show resolved Hide resolved

s2.setOptions({
tooltip: {
renderTooltip: (spreadsheet) => new CustomTooltip(spreadsheet),
},
});

expect(s2.tooltip).toBeInstanceOf(CustomTooltip);
});

test('should render sheet', () => {
const facetRenderSpy = jest
.spyOn(s2, 'buildFacet' as any)
Expand Down Expand Up @@ -963,7 +975,10 @@ describe('PivotSheet Tests', () => {
s2.store.set('test', 111);

// restore mock...
(s2.tooltip.show as jest.Mock).mockRestore();
const tooltipShow = jest
1wkk marked this conversation as resolved.
Show resolved Hide resolved
.spyOn(s2.tooltip, 'show')
.mockImplementationOnce(() => {});
tooltipShow.mockRestore();
s2.showTooltip({
position: {
x: 10,
Expand Down
5 changes: 5 additions & 0 deletions packages/s2-core/src/sheet-type/spread-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ export abstract class SpreadSheet extends EE {
} else {
this.options = customMerge(this.options, options);
}

if (reset || options.tooltip?.renderTooltip) {
1wkk marked this conversation as resolved.
Show resolved Hide resolved
this.initTooltip();
}

this.registerIcons();
}

Expand Down
26 changes: 23 additions & 3 deletions packages/s2-react/playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
type InteractionOptions,
DEFAULT_STYLE,
type InteractionCellSelectedHighlightType,
BaseTooltip,
} from '@antv/s2';
import type { Adaptive, SheetType } from '@antv/s2-shared';
import corePkg from '@antv/s2/package.json';
Expand Down Expand Up @@ -69,6 +70,12 @@ import {
import './index.less';
import { ResizeConfig } from './resize';

class ResetTooltip extends BaseTooltip {
renderContent() {
ReactDOM.render(<>Reset Tooltip</>, this.container);
}
}

const { TabPane } = Tabs;

const fieldMap = {
Expand Down Expand Up @@ -449,6 +456,21 @@ function MainLayout() {
</Tooltip>
</Space>
<Space>
<Button
size="small"
onClick={() => {
s2Ref.current?.setOptions({
tooltip: {
renderTooltip: (spreadsheet) =>
new ResetTooltip(spreadsheet),
},
});
s2Ref.current?.render();
}}
style={{ marginLeft: 20 }}
>
่‡ชๅฎšไน‰ Tooltip (s2.setOptions)
</Button>
<Popover
placement="bottomRight"
content={
Expand All @@ -471,9 +493,7 @@ function MainLayout() {
</>
}
>
<Button size="small" style={{ marginLeft: 20 }}>
ไธป้ข˜่‰ฒ่ฐƒๆ•ด
</Button>
<Button size="small">ไธป้ข˜่‰ฒ่ฐƒๆ•ด</Button>
</Popover>
<Button
danger
Expand Down