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

feat(ui-top-nav-bar): add as property to TopNavBarItem #1331

Merged
merged 1 commit into from
Oct 27, 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
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,22 @@ describe('<TopNavBarItem />', async () => {
})
})

describe('as prop', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be moved to new tests by Nandi.

it('should render item as a', async () => {
await mount(
<TopNavBarItem id="item" as='a'>
Menu Item
</TopNavBarItem>
)
const component = await TopNavBarItemLocator.find()
const button = await component.findButton()

expect(button).to.have.tagName('a')
expect(button).to.not.have.attribute('href')
})
})


describe('href prop', async () => {
it('should render item as link', async () => {
await mount(
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-top-nav-bar/src/TopNavBar/TopNavBarItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ class TopNavBarItem extends Component<TopNavBarItemProps, TopNavBarItemState> {
get itemProps(): BaseButtonProps | null {
const {
id,
as,
variant,
href: hrefOriginal,
onClick: onClickOriginal,
Expand Down Expand Up @@ -418,6 +419,7 @@ class TopNavBarItem extends Component<TopNavBarItemProps, TopNavBarItemState> {

return {
id,
as,
...this.colorProps,
...this.ariaProps,
size: this.size,
Expand Down
10 changes: 9 additions & 1 deletion packages/ui-top-nav-bar/src/TopNavBar/TopNavBarItem/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import type {
TopNavBarItemTheme,
OtherHTMLAttributes,
PropValidators,
Renderable
Renderable,
AsElementType
} from '@instructure/shared-types'

import { Drilldown } from '@instructure/ui-drilldown'
Expand Down Expand Up @@ -75,6 +76,11 @@ const topNavBarItemTooltipPropType = PropTypes.oneOfType([
])

type TopNavBarItemOwnProps = {
/**
* the element type to render as (will default to `<a>` if href is provided)
*/
as?: AsElementType

/**
* Required id, used for internal tracking,
* and it also appears as an id on the item element.
Expand Down Expand Up @@ -268,6 +274,7 @@ type TopNavBarItemStyleProps = {

const propTypes: PropValidators<PropKeys> = {
id: PropTypes.string.isRequired,
as: PropTypes.elementType,
children: PropTypes.node.isRequired,
variant: PropTypes.oneOf(['default', 'button', 'icon', 'avatar']),
status: PropTypes.oneOf(['default', 'active', 'disabled']),
Expand Down Expand Up @@ -296,6 +303,7 @@ const propTypes: PropValidators<PropKeys> = {

const allowedProps: AllowedPropKeys = [
'id',
'as',
'children',
'variant',
'status',
Expand Down
Loading