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

Hds 1672 skip link #1049

Merged
merged 9 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions packages/react/src/components/header/Header.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,37 @@ export const Minimal = (args) => {
</Header>
);
};

export const WithSkipLink = (args) => {
return (
<Header {...args} onDidChangeLanguage={languageChangedAction}>
<Header.SkipLink skipTo="#content" label="Skip To Content" />
Copy link
Contributor

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).

Copy link
Contributor

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.

<Header.ActionBar
title="Helsingin kaupunki"
titleAriaLabel="Helsingin kaupunki"
titleUrl="https://hel.fi"
titleStyle={TitleStyleType.black}
>
<Header.NavigationLanguageSelector languages={languages}>
<h3>Tietoa muilla kielillä</h3>
<Link external href="www.example.com">
Selkosuomi
</Link>
<Link external href="www.example.com">
Viittomakieli
</Link>
</Header.NavigationLanguageSelector>

<Header.ActionBarItem label="Kirjaudu" icon={IconUser} style={{ order: 10 }} id="action-bar-login">
<h3>Kirjautumisvalinnat</h3>
</Header.ActionBarItem>
</Header.ActionBar>

<Header.NavigationMenu>
<Header.NavigationLink href="#" label="Link 1" />
<Header.NavigationLink href="#" label="Link 2" />
<Header.NavigationLink href="#" label="Link 3" />
</Header.NavigationMenu>
</Header>
);
};
3 changes: 3 additions & 0 deletions packages/react/src/components/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { NavigationLink } from './components/navigationLink';
import { HeaderActionBarItemWithDropdown } from './components/headerActionBarItem';
import { NavigationLanguageSelector } from './components/navigationLanguageSelector';
import { NavigationSearch } from './components/navigationSearch';
import { SkipLink } from './components/skipLink';
import { LanguageProvider, LanguageProviderProps } from '../../context/languageContext';
// import base styles
import '../../styles/base.css';
Expand Down Expand Up @@ -51,6 +52,7 @@ interface HeaderInterface extends FC<HeaderProps> {
NavigationLink: typeof NavigationLink;
NavigationLanguageSelector: typeof NavigationLanguageSelector;
NavigationSearch: typeof NavigationSearch;
SkipLink: typeof SkipLink;
}

export const Header: HeaderInterface = ({
Expand All @@ -76,3 +78,4 @@ Header.NavigationLink = NavigationLink;

Header.NavigationLanguageSelector = NavigationLanguageSelector;
Header.NavigationSearch = NavigationSearch;
Header.SkipLink = SkipLink;
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));
}
}

}
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();
});
});
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>
);
};
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>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './SkipLink';
8 changes: 7 additions & 1 deletion site/src/docs/components/header/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default ({ children, pageContext }) => <TabsLayout pageContext={pageConte
- The only mandatory component inside the header is HeaderActionBar. Other components may be used if needed.
- HeaderNavigationBar is coming soon
- HeaderActionBar is coming soon
- The inner components should **always** be in this order: Header.UniversalBar, HeaderActionBar and HeaderNavigationBar.
- The inner components should **always** be in this order: Header.SkipLink, Header.UniversalBar, HeaderActionBar and HeaderNavigationBar.

### Variations

Expand Down Expand Up @@ -63,3 +63,9 @@ Coming soon!
#### With navigation bar

Coming soon!

#### With skip link

- Using the Header.SkipLink component is optional. Use the skip link component to help keyboard-only users skip to the main content on a page.
- See Example for Header.SkipLink <Link openInNewTab openInNewTabAriaLabel="Opens in a new tab" href="/storybook/react/?path=/story/components-header--with-skip-link">in Storybook</Link>
- The Header.SkipLink supports ariaLabel which gives possibility to define more informative text for screen readers
Loading