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: The fixed attribute does not take effect #1193

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
12 changes: 7 additions & 5 deletions src/hooks/useColumns/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,13 @@ function useColumns<RecordType>(
// >>> Insert expand column if not exist
if (!cloneColumns.includes(EXPAND_COLUMN)) {
const expandColIndex = expandIconColumnIndex || 0;
if (expandColIndex >= 0) {
console.log(expandColIndex);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除调试语句

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

if (expandColIndex >= 0 && (expandColIndex || fixed === 'left' || !fixed)) {
cloneColumns.splice(expandColIndex, 0, EXPAND_COLUMN);
}
if (fixed === 'right') {
cloneColumns.splice(baseColumns.length, 0, EXPAND_COLUMN);
}
}

// >>> Deduplicate additional expand column
Expand All @@ -197,10 +201,8 @@ function useColumns<RecordType>(
const prevColumn = baseColumns[expandColumnIndex];

let fixedColumn: FixedType | null;
if ((fixed === 'left' || fixed) && !expandIconColumnIndex) {
fixedColumn = 'left';
} else if ((fixed === 'right' || fixed) && expandIconColumnIndex === baseColumns.length) {
fixedColumn = 'right';
if (fixed) {
fixedColumn = fixed;
} else {
fixedColumn = prevColumn ? prevColumn.fixed : null;
}
Expand Down
131 changes: 16 additions & 115 deletions tests/__snapshots__/ExpandRow.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ LoadedCheerio {
exports[`Table.Expand > does not crash if scroll is not set 1`] = `
LoadedCheerio {
"0": <div
class="rc-table rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left"
class="rc-table rc-table-scroll-horizontal"
>
<div
class="rc-table-container"
Expand All @@ -148,21 +148,13 @@ LoadedCheerio {
style="overflow-x: auto; overflow-y: hidden;"
>
<table
style="min-width: 100%; table-layout: fixed;"
style="min-width: 100%; table-layout: auto;"
>
<colgroup>
<col
class="rc-table-expand-icon-col"
/>
</colgroup>
<colgroup />
<thead
class="rc-table-thead"
>
<tr>
<th
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
/>
<th
class="rc-table-cell"
scope="col"
Expand Down Expand Up @@ -218,28 +210,11 @@ LoadedCheerio {

</div>
</td>
<td
style="padding: 0px; border: 0px; height: 0px;"
>
<div
style="height: 0px; overflow: hidden;"
>

</div>
</td>
</tr>
<tr
class="rc-table-row rc-table-row-level-0"
data-row-key="0"
>
<td
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
>
<span
class="rc-table-row-expand-icon rc-table-row-collapsed"
/>
</td>
<td
class="rc-table-cell"
>
Expand All @@ -260,14 +235,6 @@ LoadedCheerio {
class="rc-table-row rc-table-row-level-0"
data-row-key="1"
>
<td
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
>
<span
class="rc-table-row-expand-icon rc-table-row-collapsed"
/>
</td>
<td
class="rc-table-cell"
>
Expand Down Expand Up @@ -323,7 +290,7 @@ LoadedCheerio {
exports[`Table.Expand > does not crash if scroll is not set 2`] = `
LoadedCheerio {
"0": <div
class="rc-table rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left"
class="rc-table rc-table-scroll-horizontal"
>
<div
class="rc-table-container"
Expand All @@ -333,21 +300,13 @@ LoadedCheerio {
style="overflow-x: auto; overflow-y: hidden;"
>
<table
style="min-width: 100%; table-layout: fixed;"
style="min-width: 100%; table-layout: auto;"
>
<colgroup>
<col
class="rc-table-expand-icon-col"
/>
</colgroup>
<colgroup />
<thead
class="rc-table-thead"
>
<tr>
<th
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
/>
<th
class="rc-table-cell"
scope="col"
Expand Down Expand Up @@ -403,28 +362,11 @@ LoadedCheerio {

</div>
</td>
<td
style="padding: 0px; border: 0px; height: 0px;"
>
<div
style="height: 0px; overflow: hidden;"
>

</div>
</td>
</tr>
<tr
class="rc-table-row rc-table-row-level-0"
data-row-key="0"
>
<td
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
>
<span
class="rc-table-row-expand-icon rc-table-row-collapsed"
/>
</td>
<td
class="rc-table-cell"
>
Expand All @@ -445,14 +387,6 @@ LoadedCheerio {
class="rc-table-row rc-table-row-level-0"
data-row-key="1"
>
<td
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
>
<span
class="rc-table-row-expand-icon rc-table-row-collapsed"
/>
</td>
<td
class="rc-table-cell"
>
Expand Down Expand Up @@ -1183,7 +1117,7 @@ LoadedCheerio {
exports[`Table.Expand > work in expandable fix 1`] = `
LoadedCheerio {
"0": <div
class="rc-table rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left"
class="rc-table rc-table-scroll-horizontal"
>
<div
class="rc-table-container"
Expand All @@ -1193,21 +1127,13 @@ LoadedCheerio {
style="overflow-x: auto; overflow-y: hidden;"
>
<table
style="width: 903px; min-width: 100%; table-layout: fixed;"
style="width: 903px; min-width: 100%; table-layout: auto;"
>
<colgroup>
<col
class="rc-table-expand-icon-col"
/>
</colgroup>
<colgroup />
<thead
class="rc-table-thead"
>
<tr>
<th
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
/>
<th
class="rc-table-cell"
scope="col"
Expand Down Expand Up @@ -1263,28 +1189,11 @@ LoadedCheerio {

</div>
</td>
<td
style="padding: 0px; border: 0px; height: 0px;"
>
<div
style="height: 0px; overflow: hidden;"
>

</div>
</td>
</tr>
<tr
class="rc-table-row rc-table-row-level-0"
data-row-key="0"
>
<td
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
>
<span
class="rc-table-row-expand-icon rc-table-row-collapsed"
/>
</td>
<td
class="rc-table-cell"
>
Expand All @@ -1305,14 +1214,6 @@ LoadedCheerio {
class="rc-table-row rc-table-row-level-0"
data-row-key="1"
>
<td
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
>
<span
class="rc-table-row-expand-icon rc-table-row-collapsed"
/>
</td>
<td
class="rc-table-cell"
>
Expand Down Expand Up @@ -1368,7 +1269,7 @@ LoadedCheerio {
exports[`Table.Expand > work in expandable fix 2`] = `
LoadedCheerio {
"0": <div
class="rc-table rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-right"
class="rc-table rc-table-fixed-column rc-table-fixed-column-gapped rc-table-scroll-horizontal"
>
<div
class="rc-table-container"
Expand Down Expand Up @@ -1411,8 +1312,8 @@ LoadedCheerio {
Gender
</th>
<th
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-right rc-table-cell-fix-right-first"
style="position: sticky; right: 0px;"
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
/>
</tr>
</thead>
Expand Down Expand Up @@ -1481,8 +1382,8 @@ LoadedCheerio {
F
</td>
<td
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-right rc-table-cell-fix-right-first"
style="position: sticky; right: 0px;"
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
>
<span
class="rc-table-row-expand-icon rc-table-row-collapsed"
Expand All @@ -1509,8 +1410,8 @@ LoadedCheerio {
M
</td>
<td
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-right rc-table-cell-fix-right-first"
style="position: sticky; right: 0px;"
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
>
<span
class="rc-table-row-expand-icon rc-table-row-collapsed"
Expand Down