-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(in-page-navigation): add vertical (#3537)
* feat(in-page-navigation): add vertical * fix: lint error * fix: overflow story
- Loading branch information
Showing
8 changed files
with
346 additions
and
92 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@twilio-paste/in-page-navigation": minor | ||
"@twilio-paste/core": minor | ||
--- | ||
|
||
[In Page Navigation] Add new `orientation` property with a vertical option. |
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
99 changes: 99 additions & 0 deletions
99
packages/paste-core/components/in-page-navigation/__tests__/vertical.spec.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,99 @@ | ||
import { render } from "@testing-library/react"; | ||
import { CustomizationProvider } from "@twilio-paste/customization"; | ||
import * as React from "react"; | ||
|
||
import { InPageNavigation, InPageNavigationItem } from "../src"; | ||
|
||
describe("InPageNavigation", () => { | ||
it("should render semantically correct with aria properly", () => { | ||
const { getByRole, getAllByRole, getByText } = render( | ||
<InPageNavigation aria-label="my-nav" orientation="vertical"> | ||
<InPageNavigationItem data-test-id="page-1" href="#"> | ||
page 1 | ||
</InPageNavigationItem> | ||
<InPageNavigationItem currentPage href="#"> | ||
page 2 | ||
</InPageNavigationItem> | ||
</InPageNavigation>, | ||
); | ||
|
||
expect(getByRole("navigation")).toHaveAttribute("aria-label", "my-nav"); | ||
expect(getAllByRole("list")).toHaveLength(1); | ||
expect(getAllByRole("listitem")).toHaveLength(2); | ||
expect(getAllByRole("link")).toHaveLength(2); | ||
expect(getByText("page 2")).toHaveAttribute("aria-current", "page"); | ||
expect(getByText("page 1")).toHaveAttribute("data-test-id", "page-1"); | ||
}); | ||
}); | ||
|
||
describe("Customization", () => { | ||
it("should set a default element name", () => { | ||
const { getByRole } = render( | ||
<CustomizationProvider | ||
baseTheme="default" | ||
theme={TestTheme} | ||
elements={{ | ||
IN_PAGE_NAVIGATION: { fontWeight: "fontWeightLight" }, | ||
IN_PAGE_NAVIGATION_ITEMS: { padding: "space40" }, | ||
IN_PAGE_NAVIGATION_ITEM: { margin: "space40" }, | ||
IN_PAGE_NAVIGATION_ITEM_ANCHOR: { fontSize: "fontSize40" }, | ||
}} | ||
> | ||
<InPageNavigation aria-label="my-nav" orientation="vertical"> | ||
<InPageNavigationItem href="#">page 1</InPageNavigationItem> | ||
</InPageNavigation> | ||
</CustomizationProvider>, | ||
); | ||
|
||
const nav = getByRole("navigation"); | ||
const list = getByRole("list"); | ||
const listitem = getByRole("listitem"); | ||
const link = getByRole("link"); | ||
|
||
expect(nav).toHaveAttribute("data-paste-element", "IN_PAGE_NAVIGATION"); | ||
expect(list).toHaveAttribute("data-paste-element", "IN_PAGE_NAVIGATION_ITEMS"); | ||
expect(listitem).toHaveAttribute("data-paste-element", "IN_PAGE_NAVIGATION_ITEM"); | ||
expect(link).toHaveAttribute("data-paste-element", "IN_PAGE_NAVIGATION_ITEM_ANCHOR"); | ||
|
||
expect(nav).toHaveStyleRule("font-weight", "400"); | ||
expect(list).toHaveStyleRule("padding", "0.75rem"); | ||
expect(listitem).toHaveStyleRule("margin", "0.75rem"); | ||
expect(link).toHaveStyleRule("font-size", "1rem"); | ||
}); | ||
|
||
it("should add custom styles to custom element names", () => { | ||
const { getByRole } = render( | ||
<CustomizationProvider | ||
baseTheme="default" | ||
theme={TestTheme} | ||
elements={{ | ||
MY_IN_PAGE_NAVIGATION: { fontWeight: "fontWeightLight" }, | ||
MY_IN_PAGE_NAVIGATION_ITEMS: { padding: "space40" }, | ||
MY_IN_PAGE_NAVIGATION_ITEM: { margin: "space40" }, | ||
MY_IN_PAGE_NAVIGATION_ITEM_ANCHOR: { fontSize: "fontSize40" }, | ||
}} | ||
> | ||
<InPageNavigation element="MY_IN_PAGE_NAVIGATION" aria-label="my-nav" orientation="vertical"> | ||
<InPageNavigationItem element="MY_IN_PAGE_NAVIGATION_ITEM" href="#"> | ||
page 1 | ||
</InPageNavigationItem> | ||
</InPageNavigation> | ||
</CustomizationProvider>, | ||
); | ||
|
||
const nav = getByRole("navigation"); | ||
const list = getByRole("list"); | ||
const listitem = getByRole("listitem"); | ||
const link = getByRole("link"); | ||
|
||
expect(nav).toHaveAttribute("data-paste-element", "MY_IN_PAGE_NAVIGATION"); | ||
expect(list).toHaveAttribute("data-paste-element", "MY_IN_PAGE_NAVIGATION_ITEMS"); | ||
expect(listitem).toHaveAttribute("data-paste-element", "MY_IN_PAGE_NAVIGATION_ITEM"); | ||
expect(link).toHaveAttribute("data-paste-element", "MY_IN_PAGE_NAVIGATION_ITEM_ANCHOR"); | ||
|
||
expect(nav).toHaveStyleRule("font-weight", "400"); | ||
expect(list).toHaveStyleRule("padding", "0.75rem"); | ||
expect(listitem).toHaveStyleRule("margin", "0.75rem"); | ||
expect(link).toHaveStyleRule("font-size", "1rem"); | ||
}); | ||
}); |
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.