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

feat(PPDSC-2118): tooltip pointer #217

Merged
merged 22 commits into from
Jun 8, 2022
Merged

Conversation

mstuartf
Copy link
Contributor

@mstuartf mstuartf commented May 31, 2022

PPDSC-2118

What

  1. Background - v1 tooltip did not have a pointer arrow or ability to adjust distance
  2. What did you do - added optional pointer element to tooltip and ability to control distance

I have done:

  • Written unit tests against changes
  • Written functional tests against the component and/or NewsKit site
  • Updated relevant documentation

I have tested manually:

  • The feature's functionality is working as expected on Chrome, Firefox, Safari and Edge
  • The screen reader reads and flows through the elements as expected.
  • There are no new errors in the browser console coming from this PR.
  • When visual test is not added, it renders correctly on different browsers and mobile viewports (Safari, Firefox, small mobile viewport, tablet)
  • The Playground feature is working as expected

Differences to ticket:

  • Did not allow for setting pointer position separately. The library that we are using doesn’t really allow for this. The position of the pointer is tied to the position of the tooltip panel (e.g. image if the panel were left and the pointer right). Unclear what the use case would be. [Confirmed with Mike M]
  • The ticket has distance as prop and an override. I only included it as an override as this seems more appropriate.
  • Pointer should just inherit background colour from the main tooltip. [Confirmed with Mike M]

Other notes:

  • Changed the tooltip element type to be a <div> rather than a <p>. This is because the pointer <div> needs to be a child of the tooltip so that it can be positioned correctly. But <div> cannot appear as a descendant of <p> (or we get a validateDOMNesting console error).
  • Updated default trigger for the tooltip to be ['hover', 'focus'], rather than just 'hover'. This is so that tooltips work with screen readers by default. [Confirmed with Xin]
  • Nested panel overrides in line with ticket spec. [Confirmed with Xin and Mike M]

mstuartf added 2 commits May 31, 2022 15:21
- <p> cannot contain the <div> required for the pointer
- add optional pointer element too tooltip
- add default offset to tooltip with ability to override
@mstuartf mstuartf added the WIP Work in progress label May 31, 2022
@github-actions github-actions bot added the feature This change contains a new feature label May 31, 2022
@newskit-engineering
Copy link
Collaborator

@mstuartf mstuartf added ready for review Please assist in getting this reviewed and removed WIP Work in progress labels Jun 1, 2022
src/tooltip/defaults.ts Outdated Show resolved Hide resolved
src/tooltip/styled.tsx Outdated Show resolved Hide resolved
src/tooltip/tooltip.tsx Outdated Show resolved Hide resolved
src/tooltip/tooltip.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@mutebg mutebg left a comment

Choose a reason for hiding this comment

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

just 1 small comment, well done 👏

src/tooltip/__tests__/__snapshots__/tooltip.test.tsx.snap Outdated Show resolved Hide resolved
src/tooltip/tooltip.tsx Outdated Show resolved Hide resolved
mutebg
mutebg previously approved these changes Jun 7, 2022
Copy link
Contributor

@Xin00163 Xin00163 left a comment

Choose a reason for hiding this comment

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

Could we add the aria-hidden attribute to tooltip like https://www.w3.org/WAI/WCAG21/Techniques/aria/ARIA1? This is something I missed in the last pr. When scanning through with screenreader, the content of the tooltip is read twice. By adding this, we can avoid redundancy. Happy to have a chat about this.

src/tooltip/__tests__/tooltip.test.tsx Show resolved Hide resolved
src/tooltip/__tests__/tooltip.test.tsx Outdated Show resolved Hide resolved
src/tooltip/tooltip.tsx Show resolved Hide resolved
src/tooltip/utils.ts Show resolved Hide resolved
mstuartf added 2 commits June 7, 2022 15:59
- To prevent screen readers reading tooltip content twice (once when focusing on the context element and once when scanning).
@mstuartf mstuartf merged commit 3041b22 into main Jun 8, 2022
@mstuartf mstuartf deleted the feat/PPDSC-2118-tooltip-pointer branch June 8, 2022 09:51
Xin00163 pushed a commit that referenced this pull request Oct 17, 2022
* feat(PPDSC-2118): change tooltip element to div

- <p> cannot contain the <div> required for the pointer

* feat(PPDSC-2118): add pointer to tooltip

- add optional pointer element too tooltip
- add default offset to tooltip with ability to override

* feat(PPDSC-2118): make sure pointer id is globally unique

* feat(PPDSC-2118): add test case to make meet coverage req

* feat(PPDSC-2118): update default tooltip trigger to include focus

* feat(PPDSC-2118): split tooltip panel style preset

- pointer and panel should both inherit background colour from tooltip style preset
- panel should have additional style preset to manage border radius and text colour

* feat(PPDSC-2118): add no pointer scenario

* feat(PPDSC-2118): update tests to assert on tooltip position

* feat(PPDSC-2118): separate tooltip panel element

* feat(PPDSC-2118): apply tooltip offset in styled component

- Move inset styling to styled component
- Update inset styling based on offset passed
- Handle non-px and MQ values for offset (distance)
- Update tests

* feat(PPDSC-2118): nest tooltip panel and pointer defaults

* feat(PPDSC-2118): set background-color separately for panel and pointer

* feat(PPDSC-2118): update theme snapshots

* feat(PPDSC-2118): stop x and y coords being passed to html

* feat(PPDSC-2118): rename tooltip title prop to content

* feat(PPDSC-2118): change showPointer to hidePointer

* feat(PPDSC-2118): add tests for offset logic utils

* feat(PPDSC-2118): add aria-hidden to tooltip

- To prevent screen readers reading tooltip content twice (once when focusing on the context element and once when scanning).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This change contains a new feature ready for review Please assist in getting this reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants