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

[DO-NOT-MERGE][Button] Add pressed state #984

Closed
wants to merge 2 commits into from

Conversation

solonaarmstrong-zz
Copy link

@solonaarmstrong-zz solonaarmstrong-zz commented Feb 7, 2019

WHY are these changes introduced?

Resolves #877

Sometimes buttons are used like a radio button, usually in a group but potentially on their own (as a toggle).

WHAT is this pull request doing?

Adds a pressed prop with associated styling.

There's not much to test, since this is only adding a CSS class.

I added a second commit with pressed states for other buttons. I'm not sure these are needed, so it's easily reversible.

How to 🎩

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

Copy-paste this code in playground/Playground.tsx:
import * as React from 'react';
import {Page, Button, Stack} from '../src';

interface State {}

export default class Playground extends React.Component<never, State> {
  render() {
    return (
      <Page title="Sales by product">
        <Stack vertical>
          <Stack>
            <Button pressed>Pressed</Button>
            <Button>Button</Button>
          </Stack>
          <Stack>
            <Button primary pressed>
              Primary pressed
            </Button>
            <Button primary>Primary</Button>
          </Stack>
          <Stack>
            <Button outline pressed>
              Outline pressed
            </Button>
            <Button outline>Outline</Button>
          </Stack>
        </Stack>
      </Page>
    );
  }
}

🎩 checklist

@BPScott BPScott temporarily deployed to polaris-react-pr-984 February 7, 2019 16:48 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-984 February 7, 2019 16:51 Inactive
@solonaarmstrong-zz solonaarmstrong-zz changed the title [Button] Add pressed state [WIP] [Button] Add pressed state Feb 7, 2019
@solonaarmstrong-zz solonaarmstrong-zz changed the title [WIP] [Button] Add pressed state [Button] Add pressed state Feb 7, 2019
@BPScott BPScott temporarily deployed to polaris-react-pr-984 February 7, 2019 17:42 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-984 February 7, 2019 17:47 Inactive
@dpersing
Copy link
Contributor

dpersing commented Feb 7, 2019

@solonaarmstrong @dleroux Could this be tied to the existing ariaPressed prop? My concern with having a style-only prop is that it doesn't have that programmatic state, and consumers would need to add both.

@solonaarmstrong-zz solonaarmstrong-zz changed the title [Button] Add pressed state [WIP] [Button] Add pressed state Feb 7, 2019
@BPScott BPScott temporarily deployed to polaris-react-pr-984 February 7, 2019 18:37 Inactive
@solonaarmstrong-zz
Copy link
Author

solonaarmstrong-zz commented Feb 7, 2019

@dpersing That would be my instinct, too, but from previous experience, it seems we don't allow one prop to have side-effects on another prop and leave it up to the consumer to implement the ariaPressed.

I was thinking this would be something we could include in the accessibility best practices.

It's in the example: https://github.com/Shopify/polaris-react/pull/984/files#diff-7e827730d5a6c8f3eb1be7bfb346d278R263

@solonaarmstrong-zz solonaarmstrong-zz changed the title [WIP] [Button] Add pressed state [Button] Add pressed state Feb 7, 2019
@dpersing
Copy link
Contributor

dpersing commented Feb 7, 2019

I was thinking this would be something we could include in the accessibility best practices.

Sounds good! I can add that.

Copy link
Contributor

@ry5n ry5n left a comment

Choose a reason for hiding this comment

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

Can we make ariaPressed and pressed do the same things, and deprecate ariaPressed? I don’t like having to apply both props either, it seems like a footgun to me. I’m pretty sure we have APIs in other places that change underlying HTML for accessibility reasons, but open to be wrong on this.

@dleroux
Copy link
Contributor

dleroux commented Feb 7, 2019

I agree, pressed should be sufficient. I should have looked at rails before implementing the ariaPressed. Great opportunity to put in practice our deprecation guidelines :)

@solonaarmstrong-zz
Copy link
Author

Deprecation it is. 🎉

@solonaarmstrong-zz
Copy link
Author

@ry5n Between you and Ben, I feel as though I'm levelling up on my vernacular.

@BPScott BPScott temporarily deployed to polaris-react-pr-984 February 8, 2019 02:39 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-984 February 8, 2019 02:43 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-984 February 8, 2019 02:48 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-984 February 8, 2019 03:05 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-984 February 8, 2019 04:06 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-984 February 12, 2019 00:17 Inactive
@ry5n
Copy link
Contributor

ry5n commented Feb 12, 2019

Cool. I’ll work out some styles for this (probably will closely match what exists in Rails) and post back here today or tomorrow (Feb 12 or 13)

@BPScott BPScott temporarily deployed to polaris-react-pr-984 February 13, 2019 23:01 Inactive
@ry5n
Copy link
Contributor

ry5n commented Feb 20, 2019

Sorry these styles took so long. It ended up being best to design them in code, so I could get a feel for the transitions and so on. I pushed up a branch with what I came up with:

Design styles for toggle button (#1060)

Preview

screen shot 2019-02-19 at 6 26 27 pm

image

@solonaarmstrong-zz
Copy link
Author

I cherry-picked your commit, @ry5n. Seemed the most straightforward.


@media (-ms-high-contrast: active) {
color: ms-high-contrast-color('button-text');
background: ms-high-contrast-color('button-text-background');
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven’t checked if these look good in Windows

@yourpalsonja
Copy link
Contributor

yourpalsonja commented Feb 20, 2019

Hey everyone, change of plans! I've talked to @ry5n @solonaarmstrong and @danrosenthal, and we're going to take the changes that have been made here, and use them to build a new ToggleButton component in polaris-next for the "Saved" button feature in BetterListFilters.

Some reasoning:

  • Not every type of Button needs to support a pressed state
  • The difference between pressed and :active can be somewhat confusing
  • We need this change quickly, and creating a "test" component in polaris-next will let us try it out with low overhead.

Once I've created the ToggleButton, I'll link to the commit here!

In the meantime, here is a commit to a WIP polaris/react branch that contains a sample version of the ToggleButton: 5c3ca4c

Leaving this PR open with a DO NOT MERGE for now, we can close it if we decide to keep ToggleButton.

@yourpalsonja yourpalsonja changed the title [Button] Add pressed state [DO-NOT-MERGE][Button] Add pressed state Feb 20, 2019
@ry5n
Copy link
Contributor

ry5n commented Feb 21, 2019

@yourpalsonja @solonaarmstrong I happened to take a look at the new guidelines for deprecation; would be worth looking over if we go ahead with this PR: https://github.com/Shopify/polaris-react/blob/master/documentation/Deprecation%20guidelines.md

@solonaarmstrong-zz
Copy link
Author

solonaarmstrong-zz commented Feb 21, 2019

@ry5n Was there something in the deprecation guideline that I missed?

@ry5n
Copy link
Contributor

ry5n commented Feb 21, 2019

The guidelines are new to me, and we would have a deprecation if we went forward with this PR, so I just thought I’d drop a reminder.

@yourpalsonja
Copy link
Contributor

@ry5n @solonaarmstrong Speaking of deprecation, I didn't include the backwards-compatible prop ariaPressed on ToggleButton. Even though it resembles Button, and accepts most of the same props, it's a different component, and we're deprecating ariaPressed anyhow. Let me know if you have a different opinion!

@solonaarmstrong-zz
Copy link
Author

It's a different component altogether, so that makes sense to me.

@yourpalsonja
Copy link
Contributor

@ry5n @dpersing @danrosenthal @dleroux How does everyone feel about closing this for now, since ToggleButton has been merged in https://github.com/Shopify/web/pull/11029? We can always re-open if needed, but closing and adding something about deprecating aria-pressed for Button to the backlog seems like a better move.

@yourpalsonja
Copy link
Contributor

See notes above.

@yourpalsonja yourpalsonja deleted the button-press-state branch March 9, 2019 01:12
@BPScott
Copy link
Member

BPScott commented Mar 26, 2019

Heya folks. I need this for some work in polaris-icons. What will be the best way to bring it back to life?

@dleroux
Copy link
Contributor

dleroux commented Mar 27, 2019

This PR specifically, or the ToggleButton in polaris-next?

@beefchimi
Copy link
Contributor

I also need this ToggleButton and will be copying it from web into our project for now.

Any ETA and it joining the Polaris family?

@yourpalsonja
Copy link
Contributor

@beefchimi We're planning on putting it in, but are waiting on feedback from a few folks that have grabbed it from web like you, so we make sure we build something that's useful and reusable. Let us know how you implemented it and it if needed any changes!

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.

7 participants