Skip to content

Commit

Permalink
Merge pull request baidu#9612 from 2betop/chore-table-safari
Browse files Browse the repository at this point in the history
style: 修复 table 在 safari 里面设置 width 无效问题 Close: baidu#9486
  • Loading branch information
hsm-lv committed Feb 29, 2024
2 parents 8e8a784 + ad06c98 commit 412d04a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/amis-core/src/store/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ export const TableStore = iRendererStore
typeof column.pristine.width === 'number'
? `width: ${column.pristine.width}px;`
: column.pristine.width
? `width: ${column.pristine.width};`
? `width: ${column.pristine.width};min-width: ${column.pristine.width};`
: '' // todo 可能需要让修改过列宽的保持相应宽度,目前这样相当于重置了
}`;
});
Expand Down
7 changes: 7 additions & 0 deletions packages/amis-core/src/utils/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ export const chromeVersion = (function getChromeVersion() {
const raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
return raw ? parseInt(raw[2], 10) : false;
})();

export const isSafari =
navigator.vendor &&
navigator.vendor.indexOf('Apple') > -1 &&
navigator.userAgent &&
navigator.userAgent.indexOf('CriOS') == -1 &&
navigator.userAgent.indexOf('FxiOS') == -1;
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ exports[`Renderer:input table add 1`] = `
<th
class="is-sticky is-sticky-right is-sticky-first-right cxd-Table-operationCell"
data-index="5"
style="right: 0px;"
style="width: 150px; min-width: 150px;"
>
<div
class="cxd-TableCell--title v-middle nowrap"
Expand Down
11 changes: 9 additions & 2 deletions packages/amis/src/renderers/Table/ColGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import React from 'react';
import {chromeVersion, type IColumn, type ITableStore} from 'amis-core';
import {
chromeVersion,
isSafari,
type IColumn,
type ITableStore
} from 'amis-core';
import {observer} from 'mobx-react';

export function ColGroup({
Expand Down Expand Up @@ -37,7 +42,9 @@ export function ColGroup({
// 低版本同时设置 thead>th
// The problem is min-width CSS property.
// Before Chrome 91, min-width was ignored on COL elements. 91 no longer ignores it.
if (typeof chromeVersion === 'number' && chromeVersion < 91) {
//
// 同时 safari 也存在类似问题,设置 colgroup>col 的 width 属性无效
if (isSafari || (typeof chromeVersion === 'number' && chromeVersion < 91)) {
React.useEffect(() => {
if (domRef.current) {
const ths = [].slice.call(
Expand Down
2 changes: 1 addition & 1 deletion packages/amis/src/renderers/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1302,8 +1302,8 @@ export default class Table extends React.Component<TableProps, object> {
if (this.resizeLine) {
return;
}
this.props.store.syncTableWidth();
this.props.store.initTableWidth();
this.props.store.syncTableWidth();
this.handleOutterScroll();
callback && setTimeout(callback, 20);
}
Expand Down

0 comments on commit 412d04a

Please sign in to comment.