-
Notifications
You must be signed in to change notification settings - Fork 225
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
Wsteama 1417 add related content link to jump to component #12157
base: latest
Are you sure you want to change the base?
Changes from 34 commits
63597ee
40a18d5
205bb6f
0f320c1
c39f71c
79238d5
6f8e6bf
a015006
16951a0
a4d8100
432c727
079522e
39f9061
0552f15
0e622ac
43ea66c
9fcf10f
732d57e
cee44d0
1bb89d4
fa1e02c
6e39739
63d4cb4
7238908
51a4037
330be29
f7e0770
63a7a59
f3386eb
3ecb949
0494f88
dfd2f14
d401bbb
6e04892
2ade0d3
ffb09bc
31214b8
516db9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ | |
*/ | ||
|
||
export const MIN_SIZE = 635 - 5; | ||
export const MAX_SIZE = 1175 + 5; | ||
export const MAX_SIZE = 1181 + 5; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,24 +12,24 @@ import idSanitiser from '../../lib/utilities/idSanitiser'; | |
import styles from './index.styles'; | ||
|
||
export interface JumpToProps { | ||
jumpToHeadings?: Array<{ heading: string }>; | ||
jumpToHeadings?: Array<{ heading: string; sanitisedId?: string }>; | ||
showRelatedContentLink?: boolean; | ||
} | ||
|
||
const eventTrackingData: EventTrackingMetadata = { | ||
componentName: 'jumpto', | ||
}; | ||
|
||
const JumpTo = ({ jumpToHeadings }: JumpToProps) => { | ||
const JumpTo = ({ jumpToHeadings, showRelatedContentLink }: JumpToProps) => { | ||
// TODO: Remove for release | ||
if (isLive()) return null; | ||
|
||
const { translations } = useContext(ServiceContext); | ||
const [hash, setHash] = useState(''); | ||
const { jumpTo = 'Jump to' } = translations?.articlePage || {}; | ||
|
||
const relatedContent = translations?.relatedContent || 'Related content'; | ||
const viewRef = useViewTracker(eventTrackingData); | ||
const clickTrackerHandler = useClickTrackerHandler(eventTrackingData); | ||
|
||
useEffect(() => { | ||
setHash(window.location.hash); | ||
}, []); | ||
|
@@ -43,7 +43,15 @@ const JumpTo = ({ jumpToHeadings }: JumpToProps) => { | |
}; | ||
|
||
const titleId = 'jump-to-heading'; | ||
|
||
if ( | ||
showRelatedContentLink && | ||
!jumpToHeadings?.some(({ heading }) => heading === relatedContent) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this part of the condition ever be hit? Or was there a re-rendering thing happening whereby its was adding If thats happening, we should try not to mutate the original data, instead taking a copy of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it was adding the link again each rerender. I have been working on trying the copy of the array in storybook as it happens there too. I will do the same in this code too when I have got it working 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea it may be good to try and construct an array of 'things to render', including the related content if applicable, so something like:
That'll take a shallow copy of the |
||
) { | ||
jumpToHeadings?.push({ | ||
heading: relatedContent, | ||
sanitisedId: 'related-content-heading', | ||
amoore108 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
} | ||
return ( | ||
<nav | ||
ref={viewRef} | ||
|
@@ -62,18 +70,17 @@ const JumpTo = ({ jumpToHeadings }: JumpToProps) => { | |
{jumpTo} | ||
</Text> | ||
<ol role="list" css={styles.list}> | ||
{jumpToHeadings?.map(({ heading }) => { | ||
const sanitisedId = idSanitiser(heading); | ||
const idWithHash = `#${sanitisedId}`; | ||
|
||
{jumpToHeadings?.map(({ heading, sanitisedId }) => { | ||
const id = sanitisedId || idSanitiser(heading); | ||
const idWithHash = `#${id}`; | ||
const isActiveId = decodeURIComponent(hash) === idWithHash; | ||
return ( | ||
<li key={idWithHash} css={styles.listItem}> | ||
<a | ||
href={idWithHash} | ||
onClick={e => linkClickHandler(e, idWithHash)} | ||
css={styles.link} | ||
data-testid={`jump-to-link-${sanitisedId}`} | ||
data-testid={`jump-to-link-${id}`} | ||
> | ||
<span | ||
css={[styles.linkText, isActiveId && styles.linkTextActive]} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth deleting the
blocks.find
stuff and just having a separate story for the related content link?Like: