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

Add a 'download' property to Button #39088

Merged
merged 2 commits into from Feb 18, 2021
Merged

Add a 'download' property to Button #39088

merged 2 commits into from Feb 18, 2021

Conversation

Hamms
Copy link
Contributor

@Hamms Hamms commented Feb 17, 2021

And restrict it to only work when the component is rendering an anchor.

Intended for use with Lesson Plan PDFs

See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download

Testing story

Added a basic unit test

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

And restrict it to only work when the component is rendering an anchor.

Intended for use with [Lesson Plan PDFs](#39011)

See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download
@Hamms Hamms requested a review from jmkulwik February 17, 2021 00:49
);
assert.equal(wrapper.find('a').prop('download'), true);

wrapper = shallow(
Copy link
Contributor

Choose a reason for hiding this comment

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

Mind splitting these into two tests? One with the anchor and the other without?

The two scenarios seem pretty separate, but happy to have my mind changed :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about writing two tests, but decided to be lazy :) I'll go ahead and un-lazy this

@@ -256,6 +266,7 @@ class Button extends React.Component {
href={disabled ? 'javascript:void(0);' : href}
target={target}
disabled={disabled}
download={download}
Copy link
Contributor

Choose a reason for hiding this comment

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

Will the new functionality be added to existing elements or only to new elements? If it's the latter, it would be better to add this to a new component so we can start moving toward <a> styling rather than <button> styling.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I follow. Do we already have a component that applies styling to anchor tags, or are you suggesting I split out that functionality entirely? If the latter, that seems like a significant task all on its own.

Copy link
Contributor

@jmkulwik jmkulwik Feb 17, 2021

Choose a reason for hiding this comment

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

Currently, Button is a catch-all component for "something clickable." This presents significant accessibility issues as the styling displays an element that looks like an html button but could be a button, a div (un-noticeable by screen readers) or an a (interpreted differently by screen readers). If this is something we don't use now, but plan to use widely, it should be split into its own component. cc @epeach

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that it's an overcomplicated component, but I think the problem is that it's too easy for us as developers to use it incorrectly and to render into the browser an HTML element that's not suited for the mode of interaction we're using. All of the elements this component is capable of rendering are suitable for different modes of user interaction, we just need to make sure that we're being intentional about what we're doing.

For example, enforcing that only anchor tags support the download property.

There are lots of ways this component could be reworked to make it more obvious to developers how to use it correctly, and that's something we should be tracking and scheduling as cross-team tech debt work. But until we are able to do that work, we do still need to be able to use the functionality we currently have.

Copy link

@epeach epeach Feb 17, 2021

Choose a reason for hiding this comment

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

Not to make this thread a party, but I'm interested in seeing if @madelynkasula (owning the component library) has an opinion on if there is an inflection point where we want to move away from previous development patterns and move towards the way we want to do them in the future?

(Edit - I was on a stale version of this thread and just saw Elijah's latest comment - for what it's worth, I agree that the technical work to break this button component apart into more semantically correct parts is out of scope for this PR.)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think Elijah's approach makes the most sense for where we're at right now. The a tag is deprecated in Button, but it will be easier for us to refactor this component if everyone is using it so that it can inform how we break this component into more semantically-correct components. (E.g., there will likely be a <Link/> that accepts download as a prop, but <Button/> will not.)

We will hit an inflection point at some point, but I think we still have some decisions to make before we get there. The component library is still in very early planning stages, but this component is very high on my list of initial components for the library for the reasons you all have brought up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm definitely looking forward to the component library work! There's a lot of potential for some real big wins there

Copy link
Contributor

@jmkulwik jmkulwik 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! Thanks for letting us work out some kinks in the accessibility & component library space!
✔️ - assuming the test gets split up

@Hamms Hamms merged commit d8c25a4 into staging Feb 18, 2021
@Hamms Hamms deleted the download-button branch February 18, 2021 21:52
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.

None yet

4 participants