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

a11y(Tooltip): "tooltip" role #6865

Open
wants to merge 42 commits into
base: develop
Choose a base branch
from

Conversation

bvandercar-vt
Copy link
Contributor

@bvandercar-vt bvandercar-vt commented Jun 25, 2024

Fixes #0000

Checklist

  • Includes tests
  • [N/A] Update documentation

Changes proposed in this pull request:

@changelog-app
Copy link

changelog-app bot commented Jun 25, 2024

Generate changelog in packages/core/changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

a11y(Tooltip): "tooltip" role

Check the box to generate changelog(s)

  • Generate changelog entry

Copy link
Contributor

@evansjohnson evansjohnson left a comment

Choose a reason for hiding this comment

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

I think we should be able to get something merged here but we should be careful here of any chance of breaking existing behavior and overriding props passed to these components.

packages/core/src/common/utils/reactUtils.ts Outdated Show resolved Hide resolved
packages/core/src/components/tooltip/tooltip.tsx Outdated Show resolved Hide resolved
packages/core/src/components/tooltip/tooltip.tsx Outdated Show resolved Hide resolved
packages/core/test/tooltip/tooltipTests.tsx Show resolved Hide resolved
@evansjohnson evansjohnson self-assigned this Jun 26, 2024
Copy link
Contributor

@evansjohnson evansjohnson left a comment

Choose a reason for hiding this comment

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

I think this is getting closer but we need to be very careful here of breaking existing behavior. We'll only be able to merge this if this can be done in a way that is a strict improvement, and doesn't negatively impact users who may have already done the work to work around this.

packages/core/src/components/tooltip/tooltip.tsx Outdated Show resolved Hide resolved
// want Popover to warn if empty, so don't wrap in element if empty.
Utils.isReactNodeEmpty(content)
? content
: Utils.ensureElement(content, undefined, { role: "tooltip", id: tooltipId })
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we can do this because a consumer may have already defined an id on the content which this would override

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Highly doubt that would ever be the case, can't imagine what other scenarios they'd be doing this for. There are many cases, such as in Popover, where we apply a bunch of props without caring what the consumer may have already applied.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should account for that case: be12eb3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@evansjohnson the other alternative solution here would be we add a prop contentProps to Popover and apply it to the div that's already wrapping the content. Then we could apply these props via that. Up to you.

Copy link
Contributor

Choose a reason for hiding this comment

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

what other scenarios they'd be doing this for

basically to fix this issue in consumer land is what I'm thinking about, or possibly adding an id used to target a tooltip in tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored, please re review, I think this concern has been solved

packages/core/src/components/popover/popover.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@evansjohnson evansjohnson left a comment

Choose a reason for hiding this comment

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

Thank you for the iteration so far on this one! In interest of reducing risk of any behavior regressions and to make sure we don't regress in the future on the behavior added here, could we add tests for:

protect existing behavior:

  • an id provided to tooltip content should not be overridden
  • a provided aria-describedby on the tooltip target should not be overridden

protect against future regressions:

  • for both children target and renderTarget:
    • an id will be added to tooltip content, used in aria-describedby added to the tooltip target
    • an existing id will be used, with relevant aria-describedby still added

packages/core/src/components/popover/popover.tsx Outdated Show resolved Hide resolved
// want Popover to warn if empty, so don't wrap in element if empty.
Utils.isReactNodeEmpty(content)
? content
: Utils.ensureElement(content, undefined, { role: "tooltip", id: tooltipId })
Copy link
Contributor

Choose a reason for hiding this comment

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

what other scenarios they'd be doing this for

basically to fix this issue in consumer land is what I'm thinking about, or possibly adding an id used to target a tooltip in tests?

packages/core/src/components/popover/popover.tsx Outdated Show resolved Hide resolved
packages/core/src/components/tooltip/tooltip.tsx Outdated Show resolved Hide resolved
packages/core/src/components/tooltip/tooltip.tsx Outdated Show resolved Hide resolved
packages/core/src/components/tooltip/tooltip.tsx Outdated Show resolved Hide resolved
const childTarget = Utils.ensureElement(React.Children.toArray(children)[0]);
const clonedTarget = childTarget
? React.cloneElement(childTarget, {
"aria-describedby": [tooltipId, childTarget.props["aria-describedby"]].filter(Boolean).join(" "),
Copy link
Contributor

Choose a reason for hiding this comment

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

tooltipId could possibly appear here twice in cases where consumers of Tooltip have already added these id/aria-describedby attributes

I'm not sure of the implications of that but it seems easy enough to guard against

Copy link
Contributor Author

@bvandercar-vt bvandercar-vt Jul 1, 2024

Choose a reason for hiding this comment

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

I don't think that would make a difference in a11y but here: 0336796

Copy link
Contributor

@evansjohnson evansjohnson left a comment

Choose a reason for hiding this comment

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

I'd like to get this merged but there's a lot of separate small stuff going on in this PR right now. Could you split out everything that you think is a simple no-op refactor to set up a smaller actual change to implement this?

@bvandercar-vt
Copy link
Contributor Author

I'd like to get this merged but there's a lot of separate small stuff going on in this PR right now. Could you split out everything that you think is a simple no-op refactor to set up a smaller actual change to implement this?

#6923

@bvandercar-vt
Copy link
Contributor Author

@evansjohnson refactored this one a little bit, which I think fixed some of your concerns. Ready for re-review!

Copy link
Contributor

@ggdouglas ggdouglas left a comment

Choose a reason for hiding this comment

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

Functionally this looks good to me, but we need to address the lint and hooks errors before merging.

const popoverClasses = classNames(Classes.TOOLTIP, Classes.intentClass(intent), popoverClassName, {
[Classes.COMPACT]: compact,
});

const contentElement = Utils.ensureElement(content);
const tooltipId = contentElement?.props?.id ?? React.useMemo(() => Utils.uniqueId("tooltip"), []);
Copy link
Contributor

Choose a reason for hiding this comment

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

The use of React.useMemo here violates the rules of hooks since it is called conditionally within the ternary.

Can we extract this default memoized value out to the top level of this component?

@@ -134,6 +177,14 @@ export class Tooltip<
},
}}
{...restProps}
renderTarget={
renderTarget &&
React.useCallback(props => renderTarget({ ...props, tooltipId }), [renderTarget, tooltipId])
Copy link
Contributor

@ggdouglas ggdouglas Sep 25, 2024

Choose a reason for hiding this comment

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

Similar to above, can we pull this React.useCallback into a variable at the top of the component such that it is not called conditionally?

contentElement &&
React.cloneElement(contentElement, {
role: tooltipRole,
id: tooltipId,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: The linter is complaining that these keys, are not sorted alphabetically. We can fix by sorting them:

React.cloneElement(contentElement, {
    id: tooltipId,
    role: tooltipRole,
});

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.

3 participants