-
Notifications
You must be signed in to change notification settings - Fork 112
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
feat: skip links #3317
feat: skip links #3317
Changes from 4 commits
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@twilio-paste/codemods': patch | ||
'@twilio-paste/core': patch | ||
--- | ||
|
||
[Codemods] include new skiplinks export from Sidebar |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@twilio-paste/account-switcher': patch | ||
'@twilio-paste/menu': patch | ||
'@twilio-paste/product-switcher': patch | ||
'@twilio-paste/core': patch | ||
--- | ||
|
||
Fixed incorrect prop types for menu based components |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@twilio-paste/sidebar': minor | ||
'@twilio-paste/core': minor | ||
--- | ||
|
||
[Sidebar] Included skip link functionality, allowing consumers an easy way to create application navigation skip links. Added three new required props `mainContentSkipLinkID`, `sidebarNavigationSkipLinkID` and `topbarSkipLinkID`. Plus three optional internationalization props to translate the skip link text |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@twilio-paste/topbar': minor | ||
'@twilio-paste/core': minor | ||
--- | ||
|
||
[Topbar] Enable application navigation by providing an ID to the topbar for users to jump to via skiplink navigation. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ const AccountSwitcherBadge = React.forwardRef<HTMLButtonElement, AccountSwitcher | |
} | ||
); | ||
|
||
// omit variant from MenuBadgePropTypes because it conflicts with AccountSwitcherBadge | ||
const {variant, ...accountSwitcherPropTypes} = MenuBadgePropTypes; | ||
AccountSwitcherBadge.displayName = 'AccountSwitcherBadge'; | ||
AccountSwitcherBadge.propTypes = MenuBadgePropTypes; | ||
AccountSwitcherBadge.propTypes = accountSwitcherPropTypes; | ||
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. Throwing errors in test and storybook |
||
export {AccountSwitcherBadge}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ const MenuItem = React.forwardRef<HTMLDivElement, MenuItemProps>( | |
|
||
export const MenuItemPropTypes = { | ||
href: PropTypes.string, | ||
variant: PropTypes.oneOf([Object.values(MenuItemVariants)]), | ||
variant: PropTypes.oneOf(Object.values(MenuItemVariants)), | ||
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. Throwing errors in test and storybook |
||
disabled: PropTypes.bool, | ||
id: PropTypes.string, | ||
onClick: PropTypes.func, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ const MenuItemCheckbox = React.forwardRef<HTMLDivElement, MenuItemCheckboxProps> | |
|
||
export const MenuItemCheckboxPropTypes = { | ||
href: PropTypes.string, | ||
variant: PropTypes.oneOf([Object.values(MenuItemVariants)]), | ||
variant: PropTypes.oneOf(Object.values(MenuItemVariants)), | ||
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. Throwing errors in test and storybook |
||
disabled: PropTypes.bool, | ||
id: PropTypes.string, | ||
onClick: PropTypes.func, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ const ProductSwitcherButton = React.forwardRef<HTMLButtonElement, ProductSwitche | |
} | ||
); | ||
|
||
// omit variant and size from MenuButtonPropTypes as we set them intenrally | ||
const {variant, size, ...productSwitcherButtonPropTypes} = MenuButtonPropTypes; | ||
ProductSwitcherButton.displayName = 'ProductSwitcherButton'; | ||
ProductSwitcherButton.propTypes = MenuButtonPropTypes; | ||
ProductSwitcherButton.propTypes = productSwitcherButtonPropTypes; | ||
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. Throwing errors in test and storybook |
||
export {ProductSwitcherButton}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as React from 'react'; | ||
import {render, screen} from '@testing-library/react'; | ||
|
||
import {SidebarSkipLinks} from '../src/SidebarSkipLinks'; | ||
|
||
describe('SkipLinks', () => { | ||
it('should render three links', () => { | ||
render(<SidebarSkipLinks mainContentSkipLinkID="ID1" sidebarNavigationSkipLinkID="ID2" topbarSkipLinkID="ID3" />); | ||
|
||
const renderedLinks = screen.getAllByRole('link'); | ||
|
||
expect(renderedLinks.length).toBe(3); | ||
expect(renderedLinks[0]).toHaveAttribute('href', '#ID1'); | ||
expect(renderedLinks[1]).toHaveAttribute('href', '#ID2'); | ||
expect(renderedLinks[2]).toHaveAttribute('href', '#ID3'); | ||
expect(screen.getByRole('link', {name: /skip to content/i})).toBeInTheDocument(); | ||
expect(screen.getByRole('link', {name: /skip to navigation/i})).toBeInTheDocument(); | ||
expect(screen.getByRole('link', {name: /skip to topbar/i})).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render translated links', () => { | ||
render( | ||
<SidebarSkipLinks | ||
mainContentSkipLinkID="ID1" | ||
sidebarNavigationSkipLinkID="ID2" | ||
topbarSkipLinkID="ID3" | ||
i18nMainContentSkipLinkText="translated main" | ||
i18nTopbarSkipLinkText="translated topbar" | ||
i18nNavigationSkipLinkText="translated nav" | ||
/> | ||
); | ||
|
||
expect(screen.getByRole('link', {name: /translated main/i})).toBeInTheDocument(); | ||
expect(screen.getByRole('link', {name: /translated nav/i})).toBeInTheDocument(); | ||
expect(screen.getByRole('link', {name: /translated topbar/i})).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render default element names', () => { | ||
render(<SidebarSkipLinks mainContentSkipLinkID="ID1" sidebarNavigationSkipLinkID="ID2" topbarSkipLinkID="ID3" />); | ||
expect(screen.getByRole('link', {name: /skip to content/i}).dataset.pasteElement).toBe('SIDEBAR_SKIPLINKS_LINK'); | ||
expect(screen.getByRole('link', {name: /skip to navigation/i}).dataset.pasteElement).toBe('SIDEBAR_SKIPLINKS_LINK'); | ||
expect(screen.getByRole('link', {name: /skip to topbar/i}).dataset.pasteElement).toBe('SIDEBAR_SKIPLINKS_LINK'); | ||
}); | ||
|
||
it('should render custom element names', () => { | ||
render( | ||
<SidebarSkipLinks | ||
mainContentSkipLinkID="ID1" | ||
sidebarNavigationSkipLinkID="ID2" | ||
topbarSkipLinkID="ID3" | ||
element="CUSTOMLINKS" | ||
/> | ||
); | ||
expect(screen.getByRole('link', {name: /skip to content/i}).dataset.pasteElement).toBe('CUSTOMLINKS_LINK'); | ||
expect(screen.getByRole('link', {name: /skip to navigation/i}).dataset.pasteElement).toBe('CUSTOMLINKS_LINK'); | ||
expect(screen.getByRole('link', {name: /skip to topbar/i}).dataset.pasteElement).toBe('CUSTOMLINKS_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.
question: No error for variant being unused?
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.
We set it in the component above. AccountSwitcher is a subset of Menu, So I want to reuse the proptypes from Menu as much as I can, but because we set variant inside account switcher, the user can't so I don't want to error for them