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

new(Tooltip): Add optional accessibilityLabel for perf #357

Merged
merged 4 commits into from
Apr 20, 2020

Conversation

williaster
Copy link
Contributor

@williaster williaster commented Apr 18, 2020

to: @milesj @stefhatcher @hayes @alecklandgraf
cc @avand @stopachka

Description

This PR adds an optional accessibilityLabel prop to the Tooltip, mostly to enable an opt-in (non-breaking) perf improvement.

Motivation and Context

Currently the content prop of Tooltip is rendered in an invisible Portal for a11y, to serve as an aria-labeledby element that is rendered whether or not the Tooltip popup is visible. This can lead to performance issues on pages with 100s of Tooltips as content is rendered at all times.

We discussed that one solution to ensure accessibility but allow for optimization is to override this behavior by specifying an aria-label (accessibilityLabel prop) to be used instead.

Note: there was some discussion about whether omission of aria-labelledby/duplication of content should be conditional on whether props.toggleOnClick === false as you could potentially have functionality in content that would not be captured with a simple label. After thinking about this more I think it could be confusing to the developer but am still open to adding it if you want.

Testing

  • CI
  • functional – aria-label and aria-labelledby work in new story

Screenshots

New example
image

Checklist

  • My code follows the style guide of this project.
  • I have updated or added documentation accordingly.
  • I have read the CONTRIBUTING document.

@airbnb-bot
Copy link
Collaborator

Size Changes

Package Diff ESM Prev ESM CJS Prev CJS
core +0.0% 549.48 KB 549.33 KB 688.99 KB 688.82 KB

Compared to master. File sizes are unminified and ungzipped.

View raw build stats

Previous (master)

{
  "apollo": {
    "esm": 10832,
    "lib": 14147
  },
  "app-shell": {
    "esm": 12906,
    "lib": 19874
  },
  "composer": {
    "esm": 68247,
    "lib": 101805
  },
  "core": {
    "esm": 562515,
    "lib": 705353
  },
  "forms": {
    "esm": 35672,
    "lib": 47577
  },
  "icons": {
    "esm": 156355,
    "lib": 205626
  },
  "layouts": {
    "esm": 15298,
    "lib": 20770
  },
  "metrics": {
    "esm": 5467,
    "lib": 7729
  },
  "test-utils": {
    "esm": 4279,
    "lib": 5937
  }
}

Current

{
  "apollo": {
    "esm": 10832,
    "lib": 14147
  },
  "app-shell": {
    "esm": 12906,
    "lib": 19874
  },
  "composer": {
    "esm": 68247,
    "lib": 101805
  },
  "core": {
    "esm": 562671,
    "lib": 705524
  },
  "forms": {
    "esm": 35672,
    "lib": 47577
  },
  "icons": {
    "esm": 156355,
    "lib": 205626
  },
  "layouts": {
    "esm": 15298,
    "lib": 20770
  },
  "metrics": {
    "esm": 5467,
    "lib": 7729
  },
  "test-utils": {
    "esm": 4279,
    "lib": 5937
  }
}

Copy link
Contributor

@milesj milesj left a comment

Choose a reason for hiding this comment

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

Slick 👏

<Spacing bottom={1}>
<Tooltip
accessibilityLabel="Override accessibility content"
content="I have an aria-labelledby instead of aria-label"
Copy link

@stopachka stopachka Apr 20, 2020

Choose a reason for hiding this comment

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

noob q: is this the other way around?

(i.e here because we added accessibelityLabel, this has an aria-label instead of an aria-labelledby)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes! good catch 😅 I swapped these around a couple times and tho I got the children text right I failed to swap the content 🙏

Copy link

@stopachka stopachka left a comment

Choose a reason for hiding this comment

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

🔥

@@ -18,6 +18,8 @@ const EMPTY_TARGET_RECT: ClientRect = {
};

export type TooltipProps = {
/** Accessibility label. If not specified, all tooltip content is duplicated in an accessibility portal rendered at all times. */
Copy link
Contributor

Choose a reason for hiding this comment

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

small nit: to change the last part of the sentence to is duplicated, rendered in an off-screen element with a separate layer.

@williaster williaster merged commit 106ce23 into master Apr 20, 2020
@williaster williaster deleted the chris--tooltip-perf-two branch April 20, 2020 17:49
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.

5 participants