Skip to content

Conversation

@carolopolo
Copy link
Contributor

@carolopolo carolopolo commented Apr 30, 2020

WHY are these changes introduced?

Fixes https://github.com/Shopify/store/issues/14834

WHAT is this pull request doing?

No matter the viewport size, it truncates the sortOption label if it doesn't fit. Previously, we were only truncating for mobile/small screens. This PR addresses running into the same problem on various screens.

How to 🎩

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

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

import {Avatar, Card, ResourceItem, ResourceList, TextStyle} from '../src';

export function Playground() {
  const [sortValue, setSortValue] = useState('DATE_MODIFIED_DESC');

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

  const items = [
    {
      id: 341,
      url: 'customers/341',
      name: 'Mae Jemison',
      location: 'Decatur, USA',
    },
    {
      id: 256,
      url: 'customers/256',
      name: 'Ellen Ochoa',
      location: 'Los Angeles, USA',
    },
  ];

  return (
    <Card>
      <ResourceList
        selectable
        selectedItems={[]}
        resourceName={resourceName}
        items={items}
        renderItem={renderItem}
        sortValue={sortValue}
        sortOptions={[
          {
            label:
              'Last shrimpy shrimp created (ascending shrimp) shrimp shrimp shrimp shrimp shrimp',
            value: 'DATE_MODIFIED_DESC',
          },
          {label: 'Oldest update', value: 'DATE_MODIFIED_ASC'},
        ]}
        onSortChange={(selected) => {
          setSortValue(selected);
          console.log(`Sort option changed to ${selected}.`);
        }}
      />
    </Card>
  );

  function renderItem(item) {
    const {id, url, name, location} = item;
    const media = <Avatar customer size="medium" name={name} />;

    return (
      <ResourceItem
        id={id}
        url={url}
        media={media}
        accessibilityLabel={`View details for ${name}`}
      >
        <h3>
          <TextStyle variation="strong">{name}</TextStyle>
        </h3>
        <div>{location}</div>
      </ResourceItem>
    );
  }
}

🎩 checklist

  • Tested on mobile
  • Tested on multiple browsers
  • 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

@carolopolo carolopolo marked this pull request as draft April 30, 2020 19:44
@github-actions
Copy link
Contributor

github-actions bot commented Apr 30, 2020

🟢 This pull request modifies 2 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/ResourceList/ResourceList.scss (total: 1)

Files potentially affected (total: 1)

@carolopolo carolopolo changed the title refactor breakpoint to include more screens [ResourceList] Trunctate long sortOption label Apr 30, 2020
@carolopolo carolopolo force-pushed the resource-list/fix-sort-overflow branch from 7e3a7a5 to c875edf Compare April 30, 2020 19:57
@carolopolo carolopolo marked this pull request as ready for review April 30, 2020 19:58
@carolopolo carolopolo requested a review from loic-d April 30, 2020 19:58
@carolopolo carolopolo self-assigned this Apr 30, 2020
@carolopolo carolopolo requested review from chloerice and dleroux April 30, 2020 19:58
Copy link
Contributor

@loic-d loic-d left a comment

Choose a reason for hiding this comment

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

🎩 LGTM
Screen Shot 2020-04-30 at 4 16 46 PM

I think it makes sense to have the ellipsis on all viewports and not just small devices.
Would be great to get a second 👀 from a Polaris expert.

@dleroux
Copy link
Contributor

dleroux commented May 4, 2020

Looks like the focus ring gets cut off with the overflow hidden:

Screen Shot 2020-05-04 at 9 55 53 AM

Screen Shot 2020-05-04 at 9 54 59 AM

@carolopolo carolopolo marked this pull request as draft May 4, 2020 16:04
// overflow: hidden;
// }

.SortWrapper {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@beefchimi this is a possible solution... tested on chrome, firefox & safari

but would love some input 🥬

Copy link
Contributor

@beefchimi beefchimi May 4, 2020

Choose a reason for hiding this comment

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

Okay, so this can actually be fixed rather easily 😄

You can replace ALL of your changed code in this file with:

.SortWrapper {
  @include layout-flex-fix;

  // Required to apply styles to the <Labelled /> component
  > * {
    max-width: 100%;
  }
}

That is the most simple solution. Two things to potentially alter:

1. Apply "layout fix" to all children
Personally, I would apply that layout-flex-fix mixin to ALL children of .HeaderContentWrapper. So, you could instead do:

.HeaderTitleWrapper,
.CheckableButtonWrapper,
.AlternateToolWrapper,
.SortWrapper,
.SelectButtonWrapper {
  @include layout-flex-fix;
}

.SortWrapper {
  // Required to apply styles to the <Labelled /> component
  > * {
    max-width: 100%;
  }
}

2. Try to avoid reaching into other components to override styles
The > * selector is specifically targeting the .Labelled direct child. It would be preferable if we did not have to apply this snowflake override style... so I'm wondering if max-width: 100% can live comfortably on the .Labelled selector within Labelled.scss. I think its worth experimenting with that change to see if it causes issues any where else <Labelled /> is used.

Explanation
We need to utilize this layout-flex-fix mixin on direct children ("flex items") of a display: flex parent in order to get truncation to work correctly. This is a very common problem/solution! All that mixin is doing is applying the following styles:

min-width: 0;
max-width: 100%;

This seems... silly, because those prop + values seem obvious and should be default behaviour.... right?!?! The short answer is: flex box items will not shrink below their minimum content size. So, if the minimum content size is computed as the full width of a sentence, it cannot be below that width in order to truncate. In comes out handy "flex fix" styling to say "well actually min-width can be 0".

For a better explanation, our very own @dfmcphee wrote a blog post on it!
https://dfmcphee.com/flex-items-and-min-width-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.

thanks so much @beefchimi! really appreciate that.

fyi for posterity's sake:

adding the max-width: 100% on the .Labelled selector in Labelled.scss results in:
image

adding the @include layout-flex-fix; to all children of .HeaderContentWrapper results in:
image

so i'm going with your very fist suggestion. thanks again for your input!

Copy link
Contributor

Choose a reason for hiding this comment

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

We could improve this further with some tweaks to the other HeaderContentWrapper, mainly to that SelectWrapper so that it has a min-width of at least the:

  • width of a checkbox +
  • spacing()

But just so other reviews know - the label of that "select checkbox" will truncate as well. Its just that Caroline's example is soooo long that it goes beyond the text label and starts encroaching onto the checkbox input. Realistically, we probably wouldn't end up in the scenario.

@carolopolo would you mind opening an issue with your 2nd screenshot to track this? You can link to this comment + include any relevant context.

@carolopolo carolopolo removed request for chloerice and dleroux May 4, 2020 16:31
Copy link
Contributor

@beefchimi beefchimi left a comment

Choose a reason for hiding this comment

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

Alternate solution suggested in my review 😄

// overflow: hidden;
// }

.SortWrapper {
Copy link
Contributor

@beefchimi beefchimi May 4, 2020

Choose a reason for hiding this comment

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

Okay, so this can actually be fixed rather easily 😄

You can replace ALL of your changed code in this file with:

.SortWrapper {
  @include layout-flex-fix;

  // Required to apply styles to the <Labelled /> component
  > * {
    max-width: 100%;
  }
}

That is the most simple solution. Two things to potentially alter:

1. Apply "layout fix" to all children
Personally, I would apply that layout-flex-fix mixin to ALL children of .HeaderContentWrapper. So, you could instead do:

.HeaderTitleWrapper,
.CheckableButtonWrapper,
.AlternateToolWrapper,
.SortWrapper,
.SelectButtonWrapper {
  @include layout-flex-fix;
}

.SortWrapper {
  // Required to apply styles to the <Labelled /> component
  > * {
    max-width: 100%;
  }
}

2. Try to avoid reaching into other components to override styles
The > * selector is specifically targeting the .Labelled direct child. It would be preferable if we did not have to apply this snowflake override style... so I'm wondering if max-width: 100% can live comfortably on the .Labelled selector within Labelled.scss. I think its worth experimenting with that change to see if it causes issues any where else <Labelled /> is used.

Explanation
We need to utilize this layout-flex-fix mixin on direct children ("flex items") of a display: flex parent in order to get truncation to work correctly. This is a very common problem/solution! All that mixin is doing is applying the following styles:

min-width: 0;
max-width: 100%;

This seems... silly, because those prop + values seem obvious and should be default behaviour.... right?!?! The short answer is: flex box items will not shrink below their minimum content size. So, if the minimum content size is computed as the full width of a sentence, it cannot be below that width in order to truncate. In comes out handy "flex fix" styling to say "well actually min-width can be 0".

For a better explanation, our very own @dfmcphee wrote a blog post on it!
https://dfmcphee.com/flex-items-and-min-width-0/

@carolopolo carolopolo force-pushed the resource-list/fix-sort-overflow branch from 65a19e4 to d781690 Compare May 4, 2020 17:59
@carolopolo carolopolo marked this pull request as ready for review May 4, 2020 17:59
Copy link
Contributor

@beefchimi beefchimi left a comment

Choose a reason for hiding this comment

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

Looks great!

// overflow: hidden;
// }

.SortWrapper {
Copy link
Contributor

Choose a reason for hiding this comment

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

We could improve this further with some tweaks to the other HeaderContentWrapper, mainly to that SelectWrapper so that it has a min-width of at least the:

  • width of a checkbox +
  • spacing()

But just so other reviews know - the label of that "select checkbox" will truncate as well. Its just that Caroline's example is soooo long that it goes beyond the text label and starts encroaching onto the checkbox input. Realistically, we probably wouldn't end up in the scenario.

@carolopolo would you mind opening an issue with your 2nd screenshot to track this? You can link to this comment + include any relevant context.

@carolopolo carolopolo merged commit f5f542d into master May 4, 2020
@carolopolo carolopolo deleted the resource-list/fix-sort-overflow branch May 4, 2020 19:05
@ghost
Copy link

ghost commented May 4, 2020

🎉 Thanks for your contribution to Polaris React!

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.

4 participants