- Notifications
You must be signed in to change notification settings - Fork 62
Add DownloadButton component #213
Conversation
35d02dc to f38dc8c Compare | This is looking great 🤩 |
| Awesome, thanks for the heads up @zackkrida! |
f38dc8c to d0f0321 Compare | axios.head.mockReset() | ||
| }) | ||
| | ||
| // TODO(@sarayourfriend) convert this to testing-library once it's possible to get the `vm` from the wrapper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is blocked by this PR testing-library/vue-testing-library#250
15bafcd to eff5cc6 Compare | name: 'DownloadButton', | ||
| components: { DropdownButton }, | ||
| props: { | ||
| formats: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very thorough validation!
| : '', | ||
| ]" | ||
| type="button" | ||
| v-bind="itemA11yProps" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change the aria-label from dropdown to something like 'Select the download file format'?
| The button works and looks amazing! I have a couple of questions about functionality. |
| const response = await axios.head(format.download_url) | ||
| return [format.extension_name, response.headers['content-length']] | ||
| } catch (e) { | ||
| return [format.extension_name, undefined] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor point but I love seeing undefined in use 😄
It should be doing that, if it's not it's a bug 😅
Yup! I think that matches the behavior on the WAI-ARIA examples but I'll double check. Update: I double checked against this example: https://www.w3.org/TR/wai-aria-practices-1.2/examples/menu-button/menu-button-actions-active-descendant.html And it looks like we're matching the behavior. The only thing that is different is that the dropdown doesn't cycle through to the end if you arrow up/down at the end or beginning of the list. That should be a trivial fix. |
zackkrida left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm seeing a few issues on this otherwise excellent work:
- See inline code suggestion for the filesize font weight
- The disjointed underline looks particularly bad, I think it'd be best just to remove the hover underline.

- I think there's still an issue with events firing multiple times, perhaps due to some event bubbling. Keyboard controls work flawlessly but clicks seem unpredictable. This video isn't the most helpful but should show some instances where 2,3, or even 5 clicks are necessary to reveal the dropdown.
CleanShot.2021-09-23.at.11.45.50.mp4
- The dropdown does not close after selecting an item, again I think because of an event double fire
This is super close to merge 🤩
src/components/DownloadButton.vue Outdated
| <span class="ml-4 selected-format"> | ||
| {{ selectedFormat.extension_name }} | ||
| </span> | ||
| <span class="ml-1 font-thin">{{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <span class="ml-1 font-thin">{{ | |
| <span class="ml-1 font-normal">{{ |
The normal weight has enough contrast with the bold and is much more legible, I think. It also appears to be what is used in Figma.
For some reason I'm not able to reproduce this... or the bug where clicking doesn't cause the dropdown to open 🤔 I'll keep digging and see if I can identify the problem though. |
| So I've just done some experimenting and discovered something interesting... I wonder if it's at the root cause of what's going on here. When you https://codesandbox.io/s/reverent-lucy-j7kf3?file=/src/App.vue I have absolutely no idea how to circumvent this... I suppose we could just not use the |
| @sarayourfriend perhaps we just remove the keydown events? Is that all we need? |
We can do that for the dropdown button I think... but for the format buttons I don't think it's possible because we need to respond to specific keys (tab, arrows, page down/up, end/home, etc) as well as the click event... I wonder if there's a way of telling the click event to only fire if it's a true click, given we're handling the keydown event ourselves 🤔 |
| Apparently you can use |
| Hmmm, actually we can't do that because we are depending on the Which also means that isn't the issue... the click and keydown events can fire at the same time and they shouldn't interact with each other in this case cause they're doing entirely different things. |
| Additionally, I'm just noticing that because the link for the download button looks like a button, it doesn't actually behave like a button (Space doesn't trigger the download, in fact it scrolls the screen) so I wonder if there's something we need to do there to handle that situation? |
@sarayourfriend I think it's okay for it to behave like a link and look like a button. |
| I think I figured out the issue with clicking the dropdown button. The click only triggers if you click the button and not the icon 🤯 |
| @sarayourfriend |
| Thanks @zackkrida ! |
I still can't figure this out... or reproduce it 😞 |
538da94 to cf94d49 Compare
zackkrida left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now looks and works perfectly 🥳. The only bit of feedback I have is that I'd like to figure out how to show the focus ring on dropdown items only when the user is using the keyboard. If someone is using the mouse with the dropdown, it's confusing to see two interaction states: the gray background of the selected item and the pink ring defaulted to the first item.

Fixes
Related to #149 by @zackkrida
Description
Adds a new DownloadButton component based on the DropdownButton component.
Technical details
Adds the
filesizedependency which is a function for displaying filesizes with their units appropriatly. It's pretty small: https://bundlephobia.com/package/filesizeTests
Most of the behavior of this component is already tested in the DropdownButton component's tests. The behavior around the localStorage would be worth testing though, so I'll add some unit tests for that (assuming JSDOM supports it)
To test this locally run
npm run storybookand navigate to/?path=/story/components-downloadbutton--defaultto test the component manually. It should even let you download the files 🙂Screenshots
Checklist
Update index.md).mainormaster).Developer Certificate of Origin
Developer Certificate of Origin