Skip to content

Commit

Permalink
[indexTable] fix for overscroll issue with when last header has `alig…
Browse files Browse the repository at this point in the history
…nment='end'` (#11885)

### WHY are these changes introduced?

Fixes #11852  <!-- link to issue if one exists -->

When adding an `alignment:"end"` to the last element of the heading
array it was causing a visible gap to occur on the right of the table
heading when scrolling right (as seen below)
![Screenshot 2024-04-11 at 17 17
44](https://github.com/Shopify/polaris/assets/37420719/f80448ef-ce0e-44b5-b40f-247f77797a46)



### WHAT is this pull request doing?

This fixes the gap by applying `overflow-x:hidden` in the styles that
control the heading that had the gap

**before**
![Screenshot 2024-04-11 at 17 17
44](https://github.com/Shopify/polaris/assets/37420719/4ff75683-e0d6-4c27-aae5-73fd7eee4c30)

**after**
![Screenshot 2024-04-11 at 17 20
46](https://github.com/Shopify/polaris/assets/37420719/ce89a95c-3b75-4504-901e-3272a8dea65e)



### How to 🎩

🖥 [Local development
instructions](https://github.com/Shopify/polaris/blob/main/README.md#install-dependencies-and-build-workspaces)
🗒 [General tophatting
guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md)
📄 [Changelog
guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog)

You can view the fix for this in storybook by going to the newly added
section "With Sortable Headings Last Element Alignment End"

 
![Screenshot 2024-04-11 at 17 23
18](https://github.com/Shopify/polaris/assets/37420719/a359e77e-21eb-4e64-8c89-ca9965a58ec6)


### 🎩 checklist

- [ ] Tested a
[snapshot](https://github.com/Shopify/polaris/blob/main/documentation/Releasing.md#-snapshot-releases)
- [ ] Tested on
[mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing)
- [ ] Tested on [multiple
browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers)
- [ ] Tested for
[accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md)
- [ ] Updated the component's `README.md` with documentation changes
- [ ] [Tophatted
documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md)
changes in the style guide
  • Loading branch information
craigcolesshopify authored Apr 12, 2024
1 parent 46d5c63 commit af80d3a
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/old-clouds-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': patch
---

[indexTable] Fixed over scroll gap on `IndexTable` for sortable last headings with `alignment="end"`
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@

&:last-child:not(.TableHeading-flush) {
padding-right: var(--p-space-300);
overflow-x: hidden;
}
}

Expand Down
191 changes: 191 additions & 0 deletions polaris-react/src/components/IndexTable/IndexTable.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3094,6 +3094,197 @@ export function WithSortableHeadings() {
);
}

export function WithSortableHeadingsLastElementAlignmentEnd() {
const [sortIndex, setSortIndex] = useState(0);
const [sortDirection, setSortDirection] =
useState<IndexTableProps['sortDirection']>('descending');

const sortToggleLabels = {
0: {ascending: 'A-Z', descending: 'Z-A'},
1: {ascending: 'Ascending', descending: 'Descending'},
2: {ascending: 'Newest', descending: 'Oldest'},
3: {ascending: 'Ascending', descending: 'Ascending'},
4: {ascending: 'A-Z', descending: 'Z-A'},
5: {ascending: 'A-Z', descending: 'Z-A'},
6: {ascending: 'A-Z', descending: 'Z-A'},
7: {ascending: 'A-Z', descending: 'Z-A'},
};

const initialRows = [
{
id: '3411',
url: '#',
name: 'Mae Jemison',
date: '2022-02-04',
location: 'Decatur, USA',
orders: 20,
amountSpent: '$2,400',
fulfillmentStatus: 'Fulfilled',
paymentStatus: 'Paid',
notes: '',
},
{
id: '2561',
url: '#',
date: '2022-01-19',
name: 'Ellen Ochoa',
location: 'Los Angeles, USA',
orders: 30,
amountSpent: '$140',
fulfillmentStatus: 'Fulfilled',
paymentStatus: 'Not paid',
notes: 'This customer lives on the 3rd floor',
},
{
id: '1245',
url: '#',
date: '2021-12-12',
name: 'Anne-Marie Johnson',
location: 'Portland, USA',
orders: 10,
amountSpent: '$250',
fulfillmentStatus: 'Fulfilled',
paymentStatus: 'Not paid',
notes: '',
},
{
id: '8741',
url: '#',
date: '2022-05-11',
name: 'Bradley Stevens',
location: 'Hialeah, USA',
orders: 5,
amountSpent: '$26',
fulfillmentStatus: 'Unfulfilled',
paymentStatus: 'Not paid',
notes: 'This customer has requested fragile delivery',
},
];
const [sortedRows, setSortedRows] = useState(
sortRows(initialRows, sortIndex, sortDirection),
);

const resourceName = {
singular: 'customer',
plural: 'customers',
};

const rows = sortedRows ?? initialRows;

const {selectedResources, allResourcesSelected, handleSelectionChange} =
useIndexResourceState(rows);

function handleClickSortHeading(index, direction) {
setSortIndex(index);
setSortDirection(direction);
const newSortedRows = sortRows(rows, index, direction);
setSortedRows(newSortedRows);
}

function sortRows(localRows, index, direction) {
return [...localRows].sort((rowA, rowB) => {
const key = index === 0 ? 'name' : 'location';
if (rowA[key] < rowB[key]) {
return direction === 'descending' ? -1 : 1;
}
if (rowA[key] > rowB[key]) {
return direction === 'descending' ? 1 : -1;
}
return 0;
});
}

const rowMarkup = rows.map(
(
{
id,
name,
date,
location,
orders,
amountSpent,
fulfillmentStatus,
paymentStatus,
notes,
},
index,
) => (
<IndexTable.Row
id={id}
key={id}
selected={selectedResources.includes(id)}
position={index}
>
<IndexTable.Cell>
<Text fontWeight="bold" as="span" variant="bodyMd">
{name}
</Text>
</IndexTable.Cell>
<IndexTable.Cell>{date}</IndexTable.Cell>
<IndexTable.Cell>
<Text as="span" alignment="end" numeric variant="bodyMd">
{orders}
</Text>
</IndexTable.Cell>
<IndexTable.Cell>
<Text as="span" alignment="end" numeric variant="bodyMd">
{amountSpent}
</Text>
</IndexTable.Cell>
<IndexTable.Cell>
<Text variant="bodyMd" as="span">
{location}
</Text>
</IndexTable.Cell>
<IndexTable.Cell>{fulfillmentStatus}</IndexTable.Cell>
<IndexTable.Cell>{paymentStatus}</IndexTable.Cell>
<IndexTable.Cell>{notes}</IndexTable.Cell>
</IndexTable.Row>
),
);

return (
<LegacyCard>
<IndexTable
condensed={useBreakpoints().smDown}
resourceName={resourceName}
itemCount={rows.length}
selectedItemsCount={
allResourcesSelected ? 'All' : selectedResources.length
}
onSelectionChange={handleSelectionChange}
headings={[
{title: 'Name'},
{title: 'Date', defaultSortDirection: 'ascending'},
{
alignment: 'end',
id: 'order-count',
title: 'Order count',
},
{
alignment: 'end',
id: 'amount-spent',
title: 'Amount spent',
},

{title: 'Location'},
{title: 'Fulfillment status'},
{title: 'Payment status'},
{title: 'Notes', alignment: 'end'},
]}
sortable={[true, true, false, true, true, false, false, true]}
sortDirection={sortDirection}
sortColumnIndex={sortIndex}
onSort={handleClickSortHeading}
sortToggleLabels={sortToggleLabels}
lastColumnSticky
>
{rowMarkup}
</IndexTable>
</LegacyCard>
);
}

export function WithSortableCustomHeadings() {
const [sortIndex, setSortIndex] = useState(0);
const [sortDirection, setSortDirection] =
Expand Down

0 comments on commit af80d3a

Please sign in to comment.