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

PD-567: IconButton accessibility, TS fixes #352

Merged
merged 12 commits into from
Apr 3, 2020

Conversation

DesignerDave
Copy link
Collaborator

@DesignerDave DesignerDave commented Apr 1, 2020

✍️ Proposed changes

  • Adds a helper type Either<> that constructs a type that requires one of a set of optional keys in an interface.
  • Changes ariaLabel to the HTML aria-label, and requires that either aria-label or aria-labelledby is present on the IconButton component.
  • If size isn't explicitly set on an Icon within IconButton, IconButton will now set the icon's size according to its own size prop.
  • Some general cleanup in Icon and IconButton.
  • Resolves an issue where TypeScript would add a triple-slash reference directive to built .d.ts files in Icon and Portal pointing to types in a Storybook package. This was a problem in TypeScript apps that don't already use Storybook.

🎟 Jira ticket: Apply accessibility attributes correctly to Icons and Icon Buttons

🛠 Types of changes

  • Tooling (updates to workspace config or internal tooling)
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

✅ Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • I have run yarn changeset and documented my changes

package.json Outdated
@@ -35,7 +35,7 @@
"prettier:check": "prettier --check \"**/*.{js,ts,tsx,json,md}\"",
"test": "jest --env jsdom",
"ts": "tsc --build tsconfig.json",
"prepublishOnly": "yarn lint && yarn test && yarn build",
"prepublishOnly": "yarn lint && yarn test && yarn build && yarn ts",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Previously, only new JS files would be built as a part of the pre-publish script, leaving potentially (though unlikely) out of date TS files in the dist directory of packages being published.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we swap the order of this then? Cuz yarn lint already runs yarn ts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Whoops, seemed to have forgotten about that. Should we actually have lint run tsc without emitting declaration files? It seems like a very side effect-y thing to be doing for a linting script.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we can do that easily then that WFM but it may be tricky to actually pull off.

Might be easier to just remove it from lint entirely and have it be its own individual task that we call individually?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried just passing --noEmit, but that didn't work out the box. I wanna keep this on our radar as an improvement we could make, because I feel pretty strongly relying on a lint script to build part of our packages is a bad idea. I'll make a ticket.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@DesignerDave DesignerDave changed the title Pd 567 icon button accessibility PD-567: IconButton accessibility, TS fixes Apr 1, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Apr 1, 2020

Size Change: +559 B (0%)

Total Size: 530 kB

Filename Size Change
packages/code/dist/index.node.js 7.74 kB +1 B
packages/code/dist/index.web.js 7.79 kB +1 B
packages/icon-button/dist/index.node.js 2.58 kB +299 B (11%) ⚠️
packages/icon-button/dist/index.web.js 2.58 kB +298 B (11%) ⚠️
packages/icon/dist/index.node.js 8.29 kB -10 B (0%)
packages/icon/dist/index.web.js 8.29 kB -9 B (0%)
packages/lib/dist/index.node.js 1.25 kB +1 B
packages/lib/dist/index.web.js 1.25 kB +1 B
packages/menu/dist/index.node.js 6.77 kB -4 B (0%)
packages/menu/dist/index.web.js 6.78 kB -4 B (0%)
packages/mongo-nav/dist/index.node.js 31.8 kB -8 B (0%)
packages/mongo-nav/dist/index.web.js 31.9 kB -7 B (0%)
ℹ️ View Unchanged
Filename Size Change
packages/badge/dist/index.node.js 1.92 kB 0 B
packages/badge/dist/index.web.js 1.92 kB 0 B
packages/box/dist/index.node.js 7.01 kB 0 B
packages/box/dist/index.web.js 7.05 kB 0 B
packages/button/dist/index.node.js 9.31 kB 0 B
packages/button/dist/index.web.js 9.35 kB 0 B
packages/card/dist/index.node.js 7.05 kB 0 B
packages/card/dist/index.web.js 7.08 kB 0 B
packages/checkbox/dist/index.node.js 74.1 kB 0 B
packages/checkbox/dist/index.web.js 74.1 kB 0 B
packages/emotion/dist/index.node.js 973 B 0 B
packages/emotion/dist/index.web.js 1.04 kB 0 B
packages/hooks/dist/index.node.js 2.72 kB 0 B
packages/hooks/dist/index.web.js 2.77 kB 0 B
packages/leafygreen-provider/dist/index.node.js 1.8 kB 0 B
packages/leafygreen-provider/dist/index.web.js 1.8 kB 0 B
packages/logo/dist/index.node.js 8.3 kB 0 B
packages/logo/dist/index.web.js 8.3 kB 0 B
packages/modal/dist/index.node.js 2.96 kB 0 B
packages/modal/dist/index.web.js 2.96 kB 0 B
packages/palette/dist/index.node.js 1.17 kB 0 B
packages/palette/dist/index.web.js 1.17 kB 0 B
packages/pipeline/dist/index.node.js 12.9 kB 0 B
packages/pipeline/dist/index.web.js 12.9 kB 0 B
packages/popover/dist/index.node.js 4.72 kB 0 B
packages/popover/dist/index.web.js 4.72 kB 0 B
packages/portal/dist/index.node.js 1.71 kB 0 B
packages/portal/dist/index.web.js 1.71 kB 0 B
packages/radio-box-group/dist/index.node.js 3.79 kB 0 B
packages/radio-box-group/dist/index.web.js 3.8 kB 0 B
packages/radio-group/dist/index.node.js 2.93 kB 0 B
packages/radio-group/dist/index.web.js 2.93 kB 0 B
packages/side-nav/dist/index.node.js 8.69 kB 0 B
packages/side-nav/dist/index.web.js 8.75 kB 0 B
packages/syntax/dist/index.node.js 24.1 kB 0 B
packages/syntax/dist/index.web.js 24.1 kB 0 B
packages/tabs/dist/index.node.js 9.51 kB 0 B
packages/tabs/dist/index.web.js 9.55 kB 0 B
packages/text-input/dist/index.node.js 3.19 kB 0 B
packages/text-input/dist/index.web.js 3.19 kB 0 B
packages/theme/dist/index.node.js 940 B 0 B
packages/theme/dist/index.web.js 940 B 0 B
packages/toggle/dist/index.node.js 4.29 kB 0 B
packages/toggle/dist/index.web.js 4.29 kB 0 B
packages/tooltip/dist/index.node.js 4.56 kB 0 B
packages/tooltip/dist/index.web.js 4.61 kB 0 B
packages/typography/dist/index.node.js 7.59 kB 0 B
packages/typography/dist/index.web.js 7.63 kB 0 B

compressed-size-action

@DesignerDave DesignerDave requested review from bruugey and hswolff April 1, 2020 16:27
@DesignerDave
Copy link
Collaborator Author

Size Change: +571 B (0%)

Total Size: 530 kB

Filename Size Change
packages/code/dist/index.node.js 7.74 kB +1 B
packages/code/dist/index.web.js 7.79 kB +1 B
packages/icon-button/dist/index.node.js 2.58 kB +306 B (11%) ⚠️
packages/icon-button/dist/index.web.js 2.59 kB +305 B (11%) ⚠️
packages/icon/dist/index.node.js 8.29 kB -10 B (0%)
packages/icon/dist/index.web.js 8.29 kB -9 B (0%)
packages/lib/dist/index.node.js 1.25 kB +1 B
packages/lib/dist/index.web.js 1.25 kB +1 B
packages/menu/dist/index.node.js 6.77 kB -4 B (0%)
packages/menu/dist/index.web.js 6.78 kB -4 B (0%)
packages/mongo-nav/dist/index.node.js 31.8 kB -8 B (0%)
packages/mongo-nav/dist/index.web.js 31.9 kB -9 B (0%)
ℹ️ View Unchanged
compressed-size-action

Lol at the warning for +305 Bytes

export type Either<T, Keys extends keyof T = keyof T> = Omit<T, Keys> &
{
[K in Keys]-?: Required<Pick<T, K>> &
Partial<Record<Exclude<Keys, K>, undefined>>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be Partial<Pick<T, Exclude<Keys, K>>>? At least, I'm pretty sure that would match your example. As it is, if I'm reading it right, this would be equivalent to

interface FirstIsRequired extends SharedInExampleInterface {
  sometimesRequired: boolean;
  requiredOtherTimes?: undefined;
}

with undefined instead of boolean. Of course, if the goal is to disallow people from providing both keys, then this is right and the example should be updated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm... I think you're right here – good catch! I tested, and confirmed this change works. As is, it was requiring that only one of the two was passed when really having both is okay.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just pushed the fix 😁

*/
export type Either<T, Keys extends keyof T = keyof T> = Omit<T, Keys> &
{
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

So just so I understand... the -?: here is removing the optionality from keyof T that's being "looped" through here, not from any of the keys that are actually output, right? Essentially just avoiding having an additional | undefined in the generated type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's my understanding. In all fairness, this is a modified version of an answer in this SO thread: https://stackoverflow.com/questions/40510611/typescript-interface-require-one-of-two-properties-to-exist

I didn't know what -? did in TS until I found this hah

package.json Outdated
@@ -35,7 +35,7 @@
"prettier:check": "prettier --check \"**/*.{js,ts,tsx,json,md}\"",
"test": "jest --env jsdom",
"ts": "tsc --build tsconfig.json",
"prepublishOnly": "yarn lint && yarn test && yarn build",
"prepublishOnly": "yarn lint && yarn test && yarn build && yarn ts",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we swap the order of this then? Cuz yarn lint already runs yarn ts.

packages/icon-button/src/IconButton.spec.tsx Outdated Show resolved Hide resolved
packages/icon-button/src/IconButton.tsx Show resolved Hide resolved
packages/icon-button/src/IconButton.tsx Show resolved Hide resolved
packages/icon-button/src/IconButton.tsx Outdated Show resolved Hide resolved
packages/icon/src/types.ts Show resolved Hide resolved
packages/lib/src/index.ts Show resolved Hide resolved
packages/icon-button/src/IconButton.tsx Show resolved Hide resolved
@DesignerDave DesignerDave requested a review from hswolff April 2, 2020 16:06
@hswolff
Copy link
Collaborator

hswolff commented Apr 3, 2020

Did you forget to push? I'm not seeing changes you said you made?

@DesignerDave
Copy link
Collaborator Author

Sorry Harry, I've been going through the comments as I address them locally. I'll re-request when I push.

@DesignerDave
Copy link
Collaborator Author

AKA now

@DesignerDave DesignerDave requested a review from hswolff April 3, 2020 16:08
@DesignerDave DesignerDave merged commit 5aafd72 into master Apr 3, 2020
@DesignerDave DesignerDave deleted the PD-567-icon-button-accessibility branch April 3, 2020 17:37
bruugey pushed a commit that referenced this pull request Aug 9, 2023
* changes

* checkpoint

* fix TS issue

* add tests for title behavior

* changesets

* format

* fix Either issue preventing multiple of the optional keys to be passed to the type

* respond to PR feedback

* remove additional ts build from prepublish script

Respond to PR feedback
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