WS-2117 Add lightweight contextual navigation attribution - #14228
WS-2117 Add lightweight contextual navigation attribution#14228LilyL0u wants to merge 29 commits into
Conversation
…ion-attribution
…ion-attribution
…on' of github.com:bbc/simorgh into WS-2117-add-lightweight-contextual-navigation-attribution
…ion-attribution
There was a problem hiding this comment.
Pull request overview
This PR updates Simorgh’s “new” header navigation behaviour so the highlighted top nav item is context-aware (Watch/Listen for relevant media pages) and improves screen reader announcements by only using “current page” when the highlight reflects a genuine location.
Changes:
- Added
primaryMediaTypedetection inPageLayoutWrapper(viablockTypes/ content blocks) and threaded it throughHeaderContainerinto the newNavigationcontainer. - Reworked top-nav active-item selection in
Navigation/index.tsxto use URL matching first, then page-type/media-type attribution, plus ashouldAnnounceflag to control “current page” announcements. - Updated
psammead-navigationlink rendering so active styling is independent of whether “current page” is announced, and added extensive navigation attribution tests/snapshots.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| ws-nextjs-app/integration/pages/live/arabic/snapshots/canonical.test.ts.snap | Snapshot update for live Arabic integration test output. |
| src/app/legacy/psammead/psammead-navigation/src/index.jsx | Adds announceCurrentPage control and decouples active underline styling from screen reader “current page” announcement. |
| src/app/legacy/containers/Header/index.jsx | Passes primaryMediaType down into the new navigation container. |
| src/app/components/PageLayoutWrapper/index.tsx | Detects primaryMediaType from page data and provides it to the header/navigation. |
| src/app/components/Navigation/index.tsx | Implements page-type/media-type based top-nav attribution and introduces shouldAnnounce behaviour for a11y. |
| src/app/components/Navigation/index.test.tsx | Adds broad unit coverage for the new attribution/announcement rules. |
| src/app/components/Navigation/snapshots/index.test.tsx.snap | Updates snapshots to reflect the new active/announcement markup. |
…ion-attribution
…ion-attribution
| pageType === TV_PAGE || | ||
| pageType === LIVE_TV_PAGE || | ||
| (pageType === MEDIA_ARTICLE_PAGE && primaryMediaType === 'video') || | ||
| (pageType === ARTICLE_PAGE && primaryMediaType === 'video') |
There was a problem hiding this comment.
Was just checking the ticket and it says an article page should highlight Home. These checks instead highlight Watch or Listen whenever a normal article contains an embedded video or audio clip.
Many ordinary news articles contain media without being video or audio pages. Should we remove the ARTICLE_PAGE checks and keep this behaviour for MEDIA_ARTICLE_PAGE only?
If the requirements changed then all good but thought i'd highlight
There was a problem hiding this comment.
I made improvements that weren't in the ticket. Will check again with Gavin.
There was a problem hiding this comment.
Gavin approves of also doing this for article pages with media 👍
| // Watch/Listen category attribution. False when Home is highlighted only as | ||
| // a last-resort default (no match, or categorized Watch/Listen doesn't exist | ||
| // in nav so falls back to Home). The bottom nav only marks items active on | ||
| // genuine URL matches and always announces. The dropdown nav never marks |
There was a problem hiding this comment.
Maybe i've misunderstood but does this match the acceptance criteria? The ticket says secondary navigation items should not be highlighted, but this says matching bottom navigation items remain active and are announced
There was a problem hiding this comment.
I think the ticket might be wrong there but will check. I would have to remove current functionality, that we only recently added, to fulfil that criteria!
There was a problem hiding this comment.
Fine to keep the sub-navigation functionality that already existed 👍
| (pageType === MEDIA_ARTICLE_PAGE && primaryMediaType === 'audio') || | ||
| (pageType === ARTICLE_PAGE && primaryMediaType === 'audio') | ||
| ) { | ||
| return topItems.length > 2 |
There was a problem hiding this comment.
Should we check that the third item is actually Listen here? Japanese is using the new navigation, but its current items are Home, Watch and News TV. On an audio page this check would highlight and announce News TV as Listen. Might need to fall back back to Home when a Listen destination is not configured?
There was a problem hiding this comment.
The problem is that there is no way of knowing whether Listen is present, or which one is Listen, unless we check against the translations for each service 😭 each url is different and can be a live radio, or on demand etc.
There was a problem hiding this comment.
Good to know about the Japanese difference though. I did not know about that. Will need to think hmm
There was a problem hiding this comment.
Yeah, checking the translated text or URLs seems unreliable. Since this is a temp solution, maybe we could use a small service-level mapping showing which services have Watch and Listen?
We could select the item from the original navigation, then fall back to Home if it is missing or hidden on Lite.
Longer term, something like a home/watch/listen value from the BFF would avoid needing this mapping. Could maybe create some sort of navigation role in the BFF, just brainstorming
There was a problem hiding this comment.
I have asked on slack as this is something we need to check as this implementaiton won't work for the Japanese service! Good spot
…ion-attribution
…ion-attribution
…ion-attribution
…ion-attribution
…ion-attribution
https://bbc.atlassian.net/browse/WS-2117
i have updated this so that the home tab is highlighted when watch or listen is not highlighted, so it acts as a default or fallback. When the home page nav item is active it will only say 'current page' if the user is actually on the home page, otherwise it will just read 'home', link and list of 3, etc.
This pull request enhances the navigation highlighting logic to more accurately reflect the user's current page context, especially for media pages (audio/video). The main improvement is the introduction of page-type and media-type-based attribution for navigation highlighting, ensuring that "Watch" or "Listen" are highlighted when appropriate, rather than always defaulting to "Home" or having nothing highlighted. This is achieved through changes in the navigation logic by passing the detected primary media type through the component tree for article pages containing media.
Navigation logic improvements:
getActiveTopIndexinNavigation/index.tsxto use page type and detectedprimaryMediaTypeto determine which top navigation item ("Home", "Watch", or "Listen") should be highlighted. This ensures that, for example, video pages highlight "Watch" and audio pages highlight "Listen", with sensible fallbacks when those items are not present. [1] [2]primaryMediaTypeis now detected inPageLayoutWrapper/index.tsxby inspectingblockTypesand content blocks, and is passed down throughHeaderContainertoNavigation. [1] [2] [3] [4]Test coverage improvements:
Navigation/index.test.tsxto verify correct navigation highlighting for a wide variety of page and media types, including articles, topics, TV, live TV, media articles, audio, and live radio pages, with and without corresponding navigation items.Type and prop updates:
PageLayoutWrapper,HeaderContainer, andNavigationcomponents to support the newprimaryMediaTypeprop. [1] [2] [3]Imports and constants:
These changes collectively ensure that navigation highlighting is context-aware, improving usability for users on media-rich pages.Resolves
A weakness of this method is that it relies on the order of the top nav always being: (1) Home, (2) Watch, (3) Listen, as the links in these items can be urls with no indication of what media they contain. The text on them also comes from the BFF, rather than being translated in Simorgh, so unless we translate the text, we don't know what it says to map it to which item it is.
It should work for radio pages, tv pages, and article and media article pages containing media.
Testing
Some example URLs
http://localhost:7081/afrique/articles/crevwjxjdgyo?renderer_env=live
http://localhost:7081/afrique/articles/cd9wdkqjgk9o?renderer_env=live
http://localhost:7081/afrique/bbc_afrique_radio/w1730k9s84l43h7?renderer_env=live
What we want to see is:
Useful Links