Skip to content

Conversation

shermanhui
Copy link
Contributor

@shermanhui shermanhui commented Oct 15, 2019

WHY are these changes introduced?

Fixes #2286

On Safari, there is 2px of margin-top and margin-bottom being applied to the FilterTrigger button in the Filter component.

WHAT is this pull request doing?

  • Added a rule to explicitly set margin to 0 in the FilterTrigger class
    since there is already no margin on Chrome/FireFox, it seemed like a
    sensible solution to explicitly ensure there is no margin applied regardless
    of browser.
  • It seemed like overkill to use the unstyled-button
    mixin so I opted for the single margin rule,
    but it could make sense to use the mixin since we want to reset this
    button element to an 'unstyled' state.

Question for Code Owners:

What would be the best practice for this Design System in this case? To use the unstyled-mixin and removing the duplicated rules such as background and border or just adding the margin rule like I've done in this PR?

In the case of using the unstyled-mixin the browser will warn that there are duplicate properties and I'm not sure if that's following best practices for this project. i.e in the screenshot below padding is duplicated as a result of using unstyled-mixin after removing background and border.

unstyled-button mixin styles displaying dupliate padding property

Before/After Images Before:

image of more filters with extra border

After:
image of filter without extra margin on safari

Copy-paste this code in playground/Playground.tsx:
import React, {useCallback, useState} from 'react';
import {
  ChoiceList,
  Page,
  Filters,
  TextField,
  TextStyle,
  Card,
  ResourceList,
  Button,
  Avatar,
} from '../src';

export function Playground() {
const [availability, setAvailability] = useState(null);
  const [productType, setProductType] = useState(null);
  const [taggedWith, setTaggedWith] = useState(null);
  const [queryValue, setQueryValue] = useState(null);

  const handleAvailabilityChange = useCallback(
    (value) => setAvailability(value),
    [],
  );
  const handleProductTypeChange = useCallback(
    (value) => setProductType(value),
    [],
  );
  const handleTaggedWithChange = useCallback(
    (value) => setTaggedWith(value),
    [],
  );
  const handleQueryValueChange = useCallback(
    (value) => setQueryValue(value),
    [],
  );
  const handleAvailabilityRemove = useCallback(() => setAvailability(null), []);
  const handleProductTypeRemove = useCallback(() => setProductType(null), []);
  const handleTaggedWithRemove = useCallback(() => setTaggedWith(null), []);
  const handleQueryValueRemove = useCallback(() => setQueryValue(null), []);

  const handleClearAll = useCallback(() => {
    handleAvailabilityRemove();
    handleProductTypeRemove();
    handleTaggedWithRemove();
    handleQueryValueRemove();
  }, [
    handleAvailabilityRemove,
    handleProductTypeRemove,
    handleQueryValueRemove,
    handleTaggedWithRemove,
  ]);

  const filters = [
    {
      key: 'taggedWith',
      label: 'Tagged with',
      filter: (
        <TextField
          label="Tagged with"
          value={taggedWith}
          onChange={handleTaggedWithChange}
          labelHidden
        />
      ),
      shortcut: true,
    },
    {
      key: 'availability',
      label: 'Availability',
      filter: (
        <ChoiceList
          title="Availability"
          titleHidden
          choices={[
            {label: 'Online Store', value: 'Online Store'},
            {label: 'Point of Sale', value: 'Point of Sale'},
            {label: 'Buy Button', value: 'Buy Button'},
          ]}
          selected={availability || []}
          onChange={handleAvailabilityChange}
          allowMultiple
        />
      ),
      shortcut: true,
    },
    {
      key: 'productType',
      label: 'Product type',
      filter: (
        <ChoiceList
          title="Product type"
          titleHidden
          choices={[
            {label: 'T-Shirt', value: 'T-Shirt'},
            {label: 'Accessory', value: 'Accessory'},
            {label: 'Gift card', value: 'Gift card'},
          ]}
          selected={productType || []}
          onChange={handleProductTypeChange}
          allowMultiple
        />
      ),
    },
  ];

  const appliedFilters = !isEmpty(taggedWith)
    ? [
        {
          key: 'taggedWith',
          label: disambiguateLabel('taggedWith', taggedWith),
          onRemove: handleTaggedWithRemove,
        },
      ]
    : [];

  function disambiguateLabel(key, value) {
    switch (key) {
      case 'taggedWith':
        return `Tagged with ${value}`;
      default:
        return value;
    }
  }

  function isEmpty(value) {
    if (Array.isArray(value)) {
      return value.length === 0;
    } else {
      return value === '' || value == null;
    }
  }

  return (
    <Page title="Playground">
      <div style={{height: '568px'}}>
        <Card>
          <ResourceList
            resourceName={{singular: 'customer', plural: 'customers'}}
            filterControl={
              <Filters
                queryValue={queryValue}
                filters={filters}
                appliedFilters={appliedFilters}
                onQueryChange={handleQueryValueChange}
                onQueryClear={handleQueryValueRemove}
                onClearAll={handleClearAll}
              >
                <div style={{paddingLeft: '8px'}}>
                  <Button onClick={() => console.log('New filter saved')}>
                    Save
                  </Button>
                </div>
              </Filters>
            }
            items={[
              {
                id: 341,
                url: 'customers/341',
                name: 'Mae Jemison',
                location: 'Decatur, USA',
              },
              {
                id: 256,
                url: 'customers/256',
                name: 'Ellen Ochoa',
                location: 'Los Angeles, USA',
              },
            ]}
            renderItem={(item) => {
              const {id, url, name, location} = item;
              const media = <Avatar customer size="medium" name={name} />;

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

🎩 checklist

@shermanhui
Copy link
Contributor Author

While creating a fix for this issue, I discovered that the :focus state was not being applied correctly in Safari and FireFox due to the way the browsers handle clicks. I need some advice as to how the team would like this issue to be resolved as it could affect other :focus related functionalities across the component library! I've created an issue #2293.

UNRELEASED.md Outdated
- Fixed `recolor-icon` Sass mixin to properly scope `$secondary-color` to the child `svg` ([#2298](https://github.com/Shopify/polaris-react/pull/2298))
- Fixed a regression with the positioning of the `Popover` component ([#2305](https://github.com/Shopify/polaris-react/pull/2305))
- Fixed issue with `Filters` component displaying an undesired margin top and bottom
on the button element on Safari ([2292](https://github.com/Shopify/polaris-react/pull/2292))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
on the button element on Safari ([2292](https://github.com/Shopify/polaris-react/pull/2292))
on the button element on Safari ([#2292](https://github.com/Shopify/polaris-react/pull/2292))

@dleroux
Copy link
Contributor

dleroux commented Dec 4, 2019

Thanks for doing this @shui91. To answer your question, I think what you did here is the best approach. No need to use unstyled-mixin since all that is needed is 1 line of CSS. Thanks for asking. I'll take a look at your other issue. You'll need to update the conflict in UNRELEASED.md, once you do that ping me and I will approve it.

@dleroux dleroux self-requested a review December 4, 2019 13:20
@shermanhui shermanhui force-pushed the fix-filters-margin-on-safari branch from c109701 to 33e44a0 Compare December 5, 2019 23:44
@shermanhui
Copy link
Contributor Author

@dleroux thanks for following up on this and the comment on the other issue! I'll make another PR for that one soon :) Appreciate the help!

@dleroux
Copy link
Contributor

dleroux commented Dec 9, 2019

@shui91 sorry about that, there was a release last week, therefore, more conflicts on the unreleased.md.

@shermanhui shermanhui force-pushed the fix-filters-margin-on-safari branch from 33e44a0 to 9ebc27f Compare December 9, 2019 18:37
@shermanhui
Copy link
Contributor Author

@dleroux resolved

@shermanhui shermanhui force-pushed the fix-filters-margin-on-safari branch from 9ebc27f to 0a3e155 Compare December 9, 2019 18:40
@dleroux
Copy link
Contributor

dleroux commented Dec 9, 2019

@shui91 looks like there are still some entries that we're in the previous release.

- on Safari the button element with FilterTrigger class
was displaying 2px of margin top and bottom due to some global
button rules; since the original implementation seems to expect 0 margin
on this button and because this only happens on Safari,
I added a rule to explicitly set margin to 0
- on a side note, it seemed like overkill to use the `unstyled-button`
mixin so I opted for the single margin rule,
but it could make sense to use the mixin since we want to reset this
button element to an 'unstyled' state.
- update UNRELEASED.md
- rebase to get up to date with master branch
@shermanhui shermanhui force-pushed the fix-filters-margin-on-safari branch from 0a3e155 to 6b5fe23 Compare January 2, 2020 23:27
@shermanhui
Copy link
Contributor Author

@dleroux Happy New Year! I've fixed the merge conflicts by rebasing master onto my branch. Hope this will do it now :)

@dleroux
Copy link
Contributor

dleroux commented Jan 2, 2020

@shui91 Happy new year to you!

Unfortunately, old entries are still in unreleased.md https://github.com/Shopify/polaris-react/pull/2292/files#diff-1f9a24a2e063326eff13af43500f8b74.

The only change in there should be yours. Sorry to do this to you, we really do appreciate the contribution! Thanks again.

- due to my fix branch being out of sync for a while, the previous
unreleased fixes were already released so they needed to be removed
@shermanhui
Copy link
Contributor Author

shermanhui commented Jan 3, 2020

https://github.com/Shopify/polaris-react/pull/2292/files#diff-1f9a24a2e063326eff13af43500f8b74

Ohhh gotcha! I didn't catch that the other fixes had already been released. 😅 UNRELEASED.md should now only have this fix now :) Thanks for the clarification @dleroux !

Copy link
Contributor

@dleroux dleroux left a comment

Choose a reason for hiding this comment

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

🎉 🙇 @shui91 Thank You!

@dleroux dleroux merged commit f11860b into Shopify:master Jan 3, 2020
@LauraAubin LauraAubin temporarily deployed to production January 16, 2020 16:22 Inactive
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.

[ResourceList] Undesirable space in "more filters" modal in Safari (macOS/iOS)

3 participants