Skip to content

Commit

Permalink
fix: 取消双击表格时浏览器默认的选中文本行为 close #2798 (#2800)
Browse files Browse the repository at this point in the history
* fix: 取消双击表格时默认选中文本的默认浏览器行为 close #2798

* test: 更新快照
  • Loading branch information
lijinke666 authored Jul 5, 2024
1 parent 3d89940 commit 5df9326
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
8 changes: 5 additions & 3 deletions packages/s2-core/src/sheet-type/spread-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,15 +744,17 @@ export abstract class SpreadSheet extends EE {
...canvasConfig,
});

this.updateContainerStyle();
this.setupContainerStyle();
}

// canvas 需要设置为 块级元素, 不然和父元素有 5px 的高度差
protected updateContainerStyle() {
protected setupContainerStyle() {
const canvas = this.getCanvasElement();

if (canvas) {
// canvas 需要设置为块级元素, 不然和父元素有 5px 的高度差
canvas.style.display = 'block';
// 避免双击 canvas 造成的外部文本选中
canvas.style.userSelect = 'none';
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ exports[`<SheetComponent/> Tests Render Tests should render editable sheet by sn
>
<canvas
height="400"
style="width: 200px; height: 200px; touch-action: none; display: block;"
style="width: 200px; height: 200px; touch-action: none; display: block; user-select: none;"
width="400"
/>
</div>
Expand Down Expand Up @@ -364,7 +364,7 @@ exports[`<SheetComponent/> Tests Render Tests should render gridAnalysis sheet b
>
<canvas
height="400"
style="width: 200px; height: 200px; touch-action: none; display: block;"
style="width: 200px; height: 200px; touch-action: none; display: block; user-select: none;"
width="400"
/>
</div>
Expand Down Expand Up @@ -622,7 +622,7 @@ exports[`<SheetComponent/> Tests Render Tests should render pivot sheet by snaps
>
<canvas
height="400"
style="width: 200px; height: 200px; touch-action: none; display: block;"
style="width: 200px; height: 200px; touch-action: none; display: block; user-select: none;"
width="400"
/>
</div>
Expand Down Expand Up @@ -880,7 +880,7 @@ exports[`<SheetComponent/> Tests Render Tests should render strategy sheet by sn
>
<canvas
height="400"
style="width: 200px; height: 200px; touch-action: none; display: block;"
style="width: 200px; height: 200px; touch-action: none; display: block; user-select: none;"
width="400"
/>
</div>
Expand Down Expand Up @@ -1138,7 +1138,7 @@ exports[`<SheetComponent/> Tests Render Tests should render table sheet by snaps
>
<canvas
height="400"
style="width: 200px; height: 200px; touch-action: none; display: block;"
style="width: 200px; height: 200px; touch-action: none; display: block; user-select: none;"
width="400"
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/s2-react/playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,7 @@ function MainLayout() {
onDataCellContextMenu={logHandler(
'onDataCellContextMenu',
)}
onDoubleClick={logHandler('onDoubleClick')}
/>
</React.StrictMode>
)}
Expand Down

0 comments on commit 5df9326

Please sign in to comment.