-
Notifications
You must be signed in to change notification settings - Fork 42
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
Hds 1672 skip link #1049
Merged
Merged
Hds 1672 skip link #1049
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
99d68e8
hds-1672: added skip link for header component
6a8ccd3
hds-1672: style fixes
7a34aae
hds-1672: pr fixes
9cde6e1
hds-1672: style fixes
7b88536
hds-1672: fixed skiplink initial top position
c0e8b3b
hds-1672: both SkipLinkProps are mandatory
44676e5
hds-1672: added ariaLabel as optional property
233b25a
hds-1672: updated reference images
262db10
hds-1672: removed unnecessary story, added info about ariaLabel to do…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+10.7 KB
packages/react/.loki/reference/chrome_iphone7_Components_Header_With_Skip_Link.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.8 KB
packages/react/.loki/reference/chrome_laptop_Components_Header_With_Skip_Link.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/react/src/components/header/components/skipLink/SkipLink.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
@use "../../../../styles/layout.scss"; | ||
|
||
.skipLink { | ||
--background-color: var(--color-white); | ||
--height: 66px; | ||
--inner-outer-spacing: 6px; | ||
--outline-color: var(--color-focus-outline); | ||
--outline-inner-color: var(--color-black-90); | ||
--outline-width: 3px; | ||
--text-color: var(--color-black-90); | ||
--top: 10px; | ||
--width: 213px; | ||
|
||
@include layout.below-large { | ||
--top: 2px; | ||
} | ||
|
||
@include layout.below-medium { | ||
--height: 60px; | ||
} | ||
|
||
display: flex; | ||
position: absolute; | ||
width: 1px; | ||
height: 1px; | ||
top: calc(-1 * (var(--height) + var(--top))); | ||
|
||
&:focus { | ||
align-items: center; | ||
background-color: var(--background-color); | ||
font-family: var(--font-default); | ||
font-weight: 500; | ||
height: var(--height); | ||
justify-content: center; | ||
left: 15px; | ||
outline: var(--outline-color) solid var(--outline-width); | ||
text-decoration: none; | ||
top: var(--top); | ||
transition: all 0.15s ease-in; | ||
width: var(--width); | ||
z-index: 99; | ||
|
||
& > .skipLinkLabel { | ||
align-items: center; | ||
color: var(--text-color); | ||
display: flex; | ||
height: calc(var(--height) - 2 * var(--inner-outer-spacing)); | ||
justify-content: center; | ||
outline: var(--outline-inner-color) solid var(--outline-width); | ||
width: calc(var(--width) - 2 * var(--inner-outer-spacing)); | ||
} | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
packages/react/src/components/header/components/skipLink/SkipLink.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import { SkipLink } from './SkipLink'; | ||
|
||
describe('<SkipToContentLink /> spec', () => { | ||
it('renders the component', () => { | ||
const { asFragment } = render(<SkipLink skipTo="content" label="skip to content" />); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
it('it should show link when tab is pressed', () => { | ||
const { asFragment, getByText } = render(<SkipLink skipTo="content" label="skip to content" />); | ||
userEvent.tab(); | ||
expect(asFragment()).toMatchSnapshot(); | ||
expect(getByText(/skip to content/)).toBeVisible(); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
packages/react/src/components/header/components/skipLink/SkipLink.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
|
||
// import core base styles | ||
import '../../../../styles/base.css'; | ||
import styles from './SkipLink.module.scss'; | ||
|
||
export type SkipLinkProps = { | ||
/** | ||
* ID of the element which is reached by clicking "skip link" shortcut | ||
*/ | ||
skipTo: string; | ||
/** | ||
* Label for skip link shortcut | ||
*/ | ||
label: string; | ||
/** | ||
* Aria label for skip link shortcut (alternative text for screen reader) | ||
*/ | ||
ariaLabel?: string; | ||
}; | ||
export const SkipLink = ({ skipTo, label, ariaLabel }: SkipLinkProps) => { | ||
const href = skipTo.startsWith('#') ? skipTo : `#${skipTo}`; | ||
|
||
return ( | ||
<a href={href} aria-label={ariaLabel} className={styles.skipLink}> | ||
<span className={styles.skipLinkLabel}>{label}</span> | ||
</a> | ||
); | ||
}; |
31 changes: 31 additions & 0 deletions
31
...ages/react/src/components/header/components/skipLink/__snapshots__/SkipLink.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<SkipToContentLink /> spec it should show link when tab is pressed 1`] = ` | ||
<DocumentFragment> | ||
<a | ||
class="skipLink" | ||
href="#content" | ||
> | ||
<span | ||
class="skipLinkLabel" | ||
> | ||
skip to content | ||
</span> | ||
</a> | ||
</DocumentFragment> | ||
`; | ||
|
||
exports[`<SkipToContentLink /> spec renders the component 1`] = ` | ||
<DocumentFragment> | ||
<a | ||
class="skipLink" | ||
href="#content" | ||
> | ||
<span | ||
class="skipLinkLabel" | ||
> | ||
skip to content | ||
</span> | ||
</a> | ||
</DocumentFragment> | ||
`; |
1 change: 1 addition & 0 deletions
1
packages/react/src/components/header/components/skipLink/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './SkipLink'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The SkipLink is quite big, it covers the whole logo and part of service name. Although the old version does that too (on laptop size) but isn't quite so big. Where did you get the designs for it? I can't find any new designs.
Edit: Actually the old implementation displays more to the left if there is space (check doc site header's Skip to content link).
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.
Now I noticed that the new Header doesn't have max width set so I can't test where this SkipLink settles if there is space on the side. So I guess we'll see to this later if need be.