Skip to content

Commit c0414ec

Browse files
authored
fix(adaptive): 修复开启自适应后 组件在 Safari 上无法渲染的问题 close #1164 (#1195)
* fix(adaptive): 修复开启自适应后 组件在Safari上无法渲染的问题 close #1164 * fix(adaptive): 修复 lint
1 parent 7a1887f commit c0414ec

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

packages/s2-react/playground/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {
5656
SheetType,
5757
PartDrillDown,
5858
PartDrillDownInfo,
59+
Adaptive,
5960
} from '@/components';
6061

6162
import './index.less';
@@ -148,7 +149,7 @@ function MainLayout() {
148149
const [showTotals, setShowTotals] = React.useState(false);
149150
const [themeCfg, setThemeCfg] = React.useState<ThemeCfg>({ name: 'default' });
150151
const [showCustomTooltip, setShowCustomTooltip] = React.useState(false);
151-
const [adaptive, setAdaptive] = React.useState(false);
152+
const [adaptive, setAdaptive] = React.useState<Adaptive>(true);
152153
const [options, setOptions] =
153154
React.useState<Partial<S2Options<React.ReactNode>>>(defaultOptions);
154155
const [dataCfg, setDataCfg] =
@@ -563,7 +564,7 @@ function MainLayout() {
563564
<Switch
564565
checkedChildren="容器宽高自适应开"
565566
unCheckedChildren="容器宽高自适应关"
566-
defaultChecked={adaptive}
567+
defaultChecked={Boolean(adaptive)}
567568
onChange={setAdaptive}
568569
/>
569570
<Switch

packages/s2-react/src/hooks/useResize.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,22 @@ export const useResize = (params: UseResizeEffectParams) => {
5252
return;
5353
}
5454
const resizeObserver = new ResizeObserver(
55-
debounce(([entry] = []) => {
55+
debounce(([entry]: ResizeObserverEntry[] = []) => {
5656
if (entry) {
5757
const [size] = entry.borderBoxSize || [];
58+
59+
// Safari 不支持 borderBoxSize 属性
5860
const width = adaptiveWidth
59-
? Math.floor(size?.inlineSize)
61+
? Math.floor(
62+
(size?.inlineSize || entry.contentRect?.width) ?? optionWidth,
63+
)
6064
: optionWidth;
6165
const height = adaptiveHeight
62-
? Math.floor(container?.getBoundingClientRect().height) // 去除 header 和 page 后才是 sheet 真正的高度
66+
? Math.floor(
67+
container?.getBoundingClientRect().height ?? optionHeight,
68+
) // 去除 header 和 page 后才是 sheet 真正的高度
6369
: optionHeight;
70+
6471
if (!adaptiveWidth && !adaptiveHeight) {
6572
return;
6673
}

0 commit comments

Comments
 (0)