This repository has been archived by the owner on Jan 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into mayank/monorepo
- Loading branch information
Showing
23 changed files
with
397 additions
and
29 deletions.
There are no files selected for viewing
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
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
52 changes: 52 additions & 0 deletions
52
packages/iTwinUI-react/src/core/SkipToContentLink/SkipToContentLink.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,52 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import SkipToContentLink from './SkipToContentLink'; | ||
|
||
it('should render link in its most basic state', () => { | ||
const { container } = render(<SkipToContentLink href='#main-content-id' />); | ||
const link = container.querySelector( | ||
'.iui-skip-to-content-link', | ||
) as HTMLElement; | ||
expect(link).toBeTruthy(); | ||
expect(link.textContent).toBe('Skip to main content'); | ||
expect(link).toHaveAttribute('href', '#main-content-id'); | ||
}); | ||
|
||
it('should render link with children', () => { | ||
const { container } = render( | ||
<SkipToContentLink href='#main-content-id'> | ||
Custom child text | ||
</SkipToContentLink>, | ||
); | ||
|
||
const link = container.querySelector( | ||
'.iui-skip-to-content-link', | ||
) as HTMLElement; | ||
expect(link).toBeTruthy(); | ||
expect(link.textContent).toBe('Custom child text'); | ||
}); | ||
|
||
it('should propagate misc props in link', () => { | ||
const { container } = render( | ||
<SkipToContentLink | ||
href='#main-content-id' | ||
className='test-class' | ||
style={{ color: 'red' }} | ||
aria-label='test-label' | ||
id='test-id' | ||
/>, | ||
); | ||
const link = container.querySelector( | ||
'.iui-skip-to-content-link', | ||
) as HTMLElement; | ||
console.log(link); | ||
expect(link).toHaveAttribute('href', '#main-content-id'); | ||
expect(link).toHaveClass('test-class'); | ||
expect(link).toHaveStyle('color: red'); | ||
expect(link).toHaveAttribute('aria-label', 'test-label'); | ||
expect(link).toHaveAttribute('id', 'test-id'); | ||
}); |
49 changes: 49 additions & 0 deletions
49
packages/iTwinUI-react/src/core/SkipToContentLink/SkipToContentLink.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,49 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import { useTheme } from '../utils'; | ||
import '@itwin/itwinui-css/css/skip-to-content.css'; | ||
|
||
export type SkipToContentLinkProps = { | ||
/** | ||
* The id of the main content that the link directs to. Don't forget the #! | ||
*/ | ||
href: string; | ||
/** | ||
* Localize 'Skip to main content' label. | ||
* @default 'Skip to main content' | ||
*/ | ||
children?: React.ReactNode; | ||
} & Omit<React.ComponentPropsWithoutRef<'a'>, 'href'>; | ||
|
||
/** | ||
* `SkipToContentLink` is for screen reader and keyboard users and will not be visible unless tabbed to. | ||
* Provides a shortcut to the main content of the page without navigating through the header, etc. | ||
* Should be placed just inside the body. Set `href` to the id of your main content component. Don't forget the `#`! | ||
* @example | ||
* <body><SkipToContentLink href='#main-content-id' /> ... </body> | ||
* <body><SkipToContentLink href='#main-content-id'>{localizedLabel}</SkipToContentLink> ... </body> | ||
*/ | ||
export const SkipToContentLink = React.forwardRef< | ||
HTMLAnchorElement, | ||
SkipToContentLinkProps | ||
>((props, ref) => { | ||
const { children = 'Skip to main content', className, ...rest } = props; | ||
|
||
useTheme(); | ||
|
||
return ( | ||
<a | ||
ref={ref} | ||
className={cx('iui-skip-to-content-link', className)} | ||
{...rest} | ||
> | ||
{children} | ||
</a> | ||
); | ||
}); | ||
|
||
export default SkipToContentLink; |
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,7 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
export { SkipToContentLink } from './SkipToContentLink'; | ||
export type { SkipToContentLinkProps } from './SkipToContentLink'; | ||
export default './SkipToContentLink'; |
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
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
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
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.