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

Feature/cdd 2285 - Addition of About Tab and dropdown functionality on mobile #588

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

luketowell
Copy link
Contributor

Description

This change moves the chart description from the header into a newly created About tab. It also includes manipulating the tabs depending on screen resolution to ensure that drop-downs are displayed on smaller devices so that mobile users can easily navigate between content.

Fixes #CDD-2285

Type of change

  • Bug fix (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)
  • This change requires a documentation update

How Has This Been Tested?

  • Unit tests
  • Playwright e2e tests
  • Mobile responsiveness
  • Accessibility (i.e. Lighthouse audit)
  • Disabled JavaScript

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • Any styles in this change follow the 'STYLES.md' guide
  • My changes are progressively enhanced with graceful degredagation for older browsers and non-JavaScript users
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@luketowell luketowell requested a review from a team as a code owner February 4, 2025 10:52
Copy link

github-actions bot commented Feb 4, 2025

Unit tests coverage

Lines Statements Branches Functions
Coverage: 96%
94.66% (1970/2081) 84.89% (489/576) 94.73% (324/342)
Tests Skipped Failures Errors Time
570 0 💤 0 ❌ 0 🔥 17.788s ⏱️

@luketowell luketowell force-pushed the feature/CDD-2285 branch 4 times, most recently from fbb71d4 to 0fef2bb Compare February 4, 2025 17:25
@luketowell luketowell force-pushed the feature/CDD-2285 branch 2 times, most recently from db773d0 to 27db6f1 Compare February 5, 2025 09:55
… functionality, new test required for mobile dropdown
onChange={onChangeFunction}
className={className}
data-testid="DropdownSelect"
aria-label="Label for the select element"
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is this aria-label for ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The aria label is there because the input doesn't require a label however aria accessibility standards specify that all "input" elements require either a label or an aria-label

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose other than the aria-label I could have a element but set it to hidden. I am not sure which is the better option

Copy link
Collaborator

@8lane 8lane Feb 12, 2025

Choose a reason for hiding this comment

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

aria-label is the accessible name that provides context to users using assistive technologies (like screen readers). If you're on a Mac I'd suggest enabling VoiceOver (Cmd+f5) and tabbing to this element to see how this might be confusing for a blind/visually impaired user. We need to be descriptive, but without overloading with information (similar to good UI/UX design for non-visually impaired users)

I'd suggest something like: “Select data view", “Choose display option” or "Select content section "

Could expand this further by appending the chart card title to it e.g.

  • “Select data view for [Chart Name]”
  • “Choose display option for [Chart Name]”
  • “Select content section for [Chart Name]”

[Chart Name] being dynamic (i.e. Choose display option for Daily deaths with COVID-19 on the death certificate by date of death.)

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 has been renamed to Choose display option for [Chart Name] which I agree is more readable.

Comment on lines 22 to 45
const displayCorrespondingContent = async (selectedValue: string) => {
// create a new array with from the original dropDown options. this prevents the splice from altering the original array data.
const options = dropdownOptions.slice()
// find the index of the selectedValue and remove the selectedValue object from the array.
const optionIndex = options.findIndex((option) => option.value === selectedValue)
options.splice(optionIndex, 1)

options.map((option) => {
const nonSelectedContent = document.getElementById(`${option.value}-${chartIdentifier}-content`)
if (nonSelectedContent) {
nonSelectedContent.setAttribute('data-state', 'inactive')
}
})

const selectedContent = document.getElementById(`${selectedValue}-${chartIdentifier}-content`)
if (selectedContent) {
selectedContent.setAttribute('data-state', 'active')
}
}

const onChangeFunction = async (optionSelected: ChangeEvent<HTMLSelectElement>) => {
optionSelected.preventDefault()
await displayCorrespondingContent(optionSelected.target.value)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just wondering why we're using DOM query selectors? React is designed specifically so we don't have to do this and allows us manipulate the DOM in a safe and immutable fashion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used the setAttribute because I couldn't figure out another way to switch between content without manually setting the attribute whilst also enabling the tab functionality in the library that we use on the full screen display. I am happy to make the change if you can suggest a better way of doing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @8lane, I have refractored this completely and changed how state is handled in order to change the tab from the dropdown. Please let me know if you think it needs other tweaks.

@luketowell luketowell changed the title Feature/cdd 2285 Feature/cdd 2285 - Addition of About Tab and dropdown functionality on mobile Feb 12, 2025
@8lane
Copy link
Collaborator

8lane commented Feb 12, 2025

image

Some responsive issues

{ value: 'about', displayText: 'About' },
]

const onChangeFunction = async (optionSelected: ChangeEvent<HTMLSelectElement>) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In React, these callback functions would typically be named with "handle" + the action. e.g. handleChange

However, given its simplicity, I would just put this function inline inside the onChange

  • You don't need to type the event then
  • Easier to read as it's in order of execution

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved in line and tested  😀

className={className}
aria-label={`${chartIdentifier} select element`}
>
{dropdownOptions.map(({ value, displayText }: DropdownOptionsProps, index) => (
Copy link
Collaborator

@8lane 8lane Feb 12, 2025

Choose a reason for hiding this comment

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

DropdownOptionsProps is redundant here. Typescript will infer this automatically

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved 👍


return (
<select
id={`#dropdown-${chartIdentifier}`}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe make this a bit more unique, just incase. Usually we prefix ids e.g. ukhsa-chart-dropdown-{id}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Id has been updated following your suggestion 👍

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.

2 participants