Skip to content

Conversation

@pamelahicks
Copy link
Contributor

@pamelahicks pamelahicks commented Apr 29, 2021

WHY are these changes introduced?

Resolves #4149
Resolves #4247

WHAT is this pull request doing?

Previous attempt

This PR adds the last prop which toggles the sticky class. The column will only be sticky above $breakpoint-small.

Screen Shot 2021-04-29 at 9 33 13 AM

Styleguide:

Screen Shot 2021-04-29 at 12 14 25 PM

This PR:

  • Adds the lastColumnSticky prop to the IndexTable which toggles the sticky class. The column will only be sticky above $breakpoint-small.
  • Enables an optional sticky least heading if it is not marked as hidden.
  • Brings back the sticky cell/heading "borders" by replacing the box-shadows which were no longer working on sticky-positioned cells in Chrome.
  • Promotes the sticky-cell z-index from 30 to 31 to avoid collisions with focused TextFields (which are z-index: 30).

Approach

Prop

The previous attempt (collapsed above) simply added a last prop to a cell to make it stick, but I decided to apply a prop lastColumnSticky to the table instead. This is to allow easy access to the prop for the purposes of adding it to the last heading, in response to this comment.

Cell borders

The styles were refactored to re-add the missing cell "borders" on the sticky cells. I opted to go with filter: drop-shadow because like box-shadow, it does not add height or width to the box, and has acceptable bowser support of 97.08% (source), which is even better than the support for position: sticky.

How to 🎩

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

Copy-paste this code in playground/Playground.tsx:
import React from 'react';

import {
  Card,
  IndexTable,
  Page,
  TextField,
  TextStyle,
  useIndexResourceState,
} from '../src';

export function Playground() {
  const customers = [
    {
      id: '3411',
      url: 'customers/341',
      name: 'Mae Jemison',
      location: 'Decatur, USA',
      orders: 20,
      note: '',
      amountSpent: '$2,400',
      status: 'success',
    },
    {
      id: '2561',
      url: 'customers/256',
      name: 'Ellen Ochoa',
      location: 'Los Angeles, USA',
      orders: 30,
      note: 'Mail invoice to head office',
      amountSpent: '$140',
    },
    {
      id: '4567',
      url: 'customers/765',
      name: 'Ellen Ochoa',
      location: 'Los Angeles, USA',
      orders: 30,
      note: '',
      amountSpent: '$140',
      status: 'subdued',
    },
  ];
  const resourceName = {
    singular: 'customer',
    plural: 'customers',
  };

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

  const rowMarkup = customers.map(
    ({id, name, location, orders, note, amountSpent, status}, index) => (
      <IndexTable.Row
        id={id}
        key={id}
        selected={selectedResources.includes(id)}
        position={index}
        status={status}
      >
        <IndexTable.Cell>
          <TextStyle variation="strong">{name}</TextStyle>
        </IndexTable.Cell>
        <IndexTable.Cell>{location}</IndexTable.Cell>
        <IndexTable.Cell>{orders}</IndexTable.Cell>
        <IndexTable.Cell>
          <TextField
            value={note}
            label="Note"
            labelHidden
            onChange={() => {}}
          />
        </IndexTable.Cell>
        <IndexTable.Cell>{amountSpent}</IndexTable.Cell>
      </IndexTable.Row>
    ),
  );

  return (
    <Page title="Playground">
      <Card>
        <IndexTable
          resourceName={resourceName}
          itemCount={customers.length}
          selectedItemsCount={
            allResourcesSelected ? 'All' : selectedResources.length
          }
          onSelectionChange={handleSelectionChange}
          headings={[
            {title: 'Name'},
            {title: 'Location'},
            {title: 'Order count'},
            {title: 'Note'},
            {title: 'Amount spent', hidden: false},
          ]}
          lastColumnSticky
        >
          {rowMarkup}
        </IndexTable>
      </Card>
    </Page>
  );
}

Style guide (Chrome):

chrome.2.55.03.PM.mov

Chrome with the last heading hidden:

chrome-hidden.mov

Firefox:

Firefox.mov

Safari:

safari.mov

iOS Safari: https://user-images.githubusercontent.com/13036921/124321724-3221b780-db4c-11eb-871f-a893ee93868a.jpeg

Condensed (Chrome):
Screen Shot 2021-07-02 at 4 18 55 PM

🎩 checklist

  • Tested on mobile
    • iOS Safari
  • Tested on multiple browsers
    • Chrome
    • Firefox
    • Safari
  • Tested for accessibility
  • Updated the component's README.md with documentation changes
  • Tophatted documentation changes in the style guide
  • For visual design changes, pinged one of @ HYPD, @ mirualves, @ sarahill, or @ ry5n to update the Polaris UI kit

@pamelahicks pamelahicks self-assigned this Apr 29, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Apr 29, 2021

🟢 This pull request modifies 5 files and might impact 1 other files.

Details:
All files potentially affected (total: 1)
📄 UNRELEASED.md (total: 0)

Files potentially affected (total: 0)

🎨 src/components/IndexTable/IndexTable.scss (total: 1)

Files potentially affected (total: 1)

📄 src/components/IndexTable/README.md (total: 0)

Files potentially affected (total: 0)

🧩 src/components/IndexTable/components/Cell/Cell.tsx (total: 1)

Files potentially affected (total: 1)

🧩 src/components/IndexTable/components/Cell/tests/Cell.test.tsx (total: 0)

Files potentially affected (total: 0)

@pamelahicks pamelahicks force-pushed the IndexTable-last-sticky-cell branch from e1a8503 to 25360e7 Compare April 29, 2021 16:00
@pamelahicks pamelahicks changed the title [WIP][IndexTable] Add sticky last cell [IndexTable] Add sticky last cell Apr 29, 2021
@pamelahicks pamelahicks marked this pull request as ready for review April 29, 2021 16:26
Copy link
Member

@AndrewMusgrave AndrewMusgrave left a comment

Choose a reason for hiding this comment

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

Screen Recording 2021-05-04 at 12 57 38 PM

Notice two things while 🎩 to get your thoughts on

  1. The last cell sticky border is always active
  2. The column header doesn't stick with the cell

@alex-page alex-page force-pushed the main branch 7 times, most recently from 2c6e842 to d2611d6 Compare June 11, 2021 16:24
@pamelahicks pamelahicks force-pushed the IndexTable-last-sticky-cell branch from 25360e7 to 7c5b28e Compare June 29, 2021 00:13
@github-actions
Copy link
Contributor

github-actions bot commented Jun 29, 2021

size-limit report

Path Size
cjs 142.35 KB (+0.1% 🔺)
esm 96.09 KB (+0.16% 🔺)
esnext 139.25 KB (+0.21% 🔺)
css 33.72 KB (+0.4% 🔺)

Comment on lines -190 to -194
.TableHeading-last {
position: sticky;
right: 0;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This wasn't being referenced in any of the components.

@pamelahicks pamelahicks removed request for kyledurand and xie June 29, 2021 00:26
@pamelahicks pamelahicks force-pushed the IndexTable-last-sticky-cell branch 2 times, most recently from 9733aaa to cc90df7 Compare July 2, 2021 18:24
$index-table-stacking-order: (
cell: 1,
sticky-cell: 30,
sticky-cell: 31,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A focused TextField has a z-index of 30, so this one was bumped up to avoid weirdness when using them together. 31 is not used elsewhere.

Before:

z-before.mov

After:

z-after.mov

@pamelahicks pamelahicks force-pushed the IndexTable-last-sticky-cell branch from cc90df7 to 2597850 Compare July 2, 2021 19:26
Comment on lines -97 to -99
@include breakpoint-after($breakpoint-small) {
box-shadow: 0 rem(-1px) 0 0 var(--p-divider);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No longer needed because the "border" appears on the TableRow

toggle: toggleHasMoreLeftColumns,
} = useToggle(false);

const onboardingScrollButtons = useRef(false);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This ref isn't being used by anything in this file and never gets toggled to true 🤔

Comment on lines -243 to -245
if (!canScrollRight) {
onboardingScrollButtons.current = false;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{title: 'Name'},
{title: 'Location'},
{title: 'Order count'},
{title: 'Amount spent', hidden: false},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the optional hidden here to bring attention that it could be set to true as well.

@pamelahicks
Copy link
Contributor Author

Notice two things while 🎩 to get your thoughts on

  1. The last cell sticky border is always active
  2. The column header doesn't stick with the cell

@AndrewMusgrave I re-worked this PR to take your two points into consideration! The PR's description has been updated.

Copy link
Member

@chloerice chloerice left a comment

Choose a reason for hiding this comment

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

Tested in all supported browsers and on mobile and this works great 🙌🏽 Thanks for contributing @pamelahicks! 💟

Copy link
Member

@AndrewMusgrave AndrewMusgrave left a comment

Choose a reason for hiding this comment

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

Left a minor comment. LGTM, nice work ✅ !!

@pamelahicks pamelahicks force-pushed the IndexTable-last-sticky-cell branch from fbfebce to 4da6801 Compare August 3, 2021 22:08
@pamelahicks pamelahicks merged commit 2cc1198 into main Aug 3, 2021
@pamelahicks pamelahicks deleted the IndexTable-last-sticky-cell branch August 3, 2021 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recently, I found that the indextable component of Polaris has problems when displaying, how can I solve it? [IndexTable] Add sticky last column

3 participants