Skip to content

Nav bar fixes #38

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

Merged
merged 4 commits into from
Jun 13, 2024
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openstax/ui-components",
"version": "1.7.8",
"version": "1.7.9",
"license": "MIT",
"source": "./src/index.ts",
"types": "./dist/index.d.ts",
Expand Down
12 changes: 6 additions & 6 deletions src/components/NavBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { navDesktopHeight, navMobileHeight } from '../../src/constants';
import * as Constants from '../../src/constants';
import styled, { css } from 'styled-components';
import theme from '../../src/theme';
import { NavBarLogo as OpenstaxLogo } from './NavBarLogo';
Expand Down Expand Up @@ -44,18 +44,18 @@ type NavBarProps = React.PropsWithChildren<{
justifyContent?: string;
}>

export const NavBar = ({ logo = false, maxWidth, ...props }: NavBarProps) => {
export const NavBar = ({ logo = false, maxWidth, navDesktopHeight, navMobileHeight, justifyContent, ...props }: NavBarProps) => {
const logoIsObject = typeof logo === 'object';
const renderAnchor = logoIsObject && 'href' in logo;
const {alt = 'OpenStax Logo', ...anchorProps} = logoIsObject ? logo : {};
const logoComponent = logo ? <OpenstaxLogo alt={alt} /> : null;

return <BarWrapper>
return <BarWrapper role="toolbar" {...props}>
<StyledNavBar
maxWidth={maxWidth}
navDesktopHeight={props.navDesktopHeight || navDesktopHeight}
navMobileHeight={props.navMobileHeight || navMobileHeight}
justifyContent={props.justifyContent}
navDesktopHeight={navDesktopHeight || Constants.navDesktopHeight}
navMobileHeight={navMobileHeight || Constants.navMobileHeight}
justifyContent={justifyContent}
>
{renderAnchor ? <a {...anchorProps}>{logoComponent}</a> : logoComponent}
{props.children}
Expand Down
14 changes: 14 additions & 0 deletions src/components/Radio.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Radio } from './Radio';
import renderer from 'react-test-renderer';
import { render, fireEvent } from '@testing-library/react';

describe('Radio', () => {
it('matches snapshot', () => {
Expand All @@ -8,4 +9,17 @@ describe('Radio', () => {
).toJSON();
expect(tree).toMatchSnapshot();
});

it('matches disabled snapshot', () => {
const tree = renderer.create(
<Radio disabled>Disabled</Radio>
).toJSON();
expect(tree).toMatchSnapshot();
});

it('calls onFocus handler', () => {
const { getByRole } = render(<Radio tooltipText='hi'>Click Me</Radio>);
const radioButton = getByRole('radio');
fireEvent.focus(radioButton);
});
});
7 changes: 7 additions & 0 deletions src/components/Tooltip.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ describe('Tooltip', () => {
).toJSON();
expect(tree).toMatchSnapshot();
});

it('uses icon', () => {
const tree = renderer.create(
<TooltipGroup isOpen={false} placement='right' icon={'icon'}>Tooltip content</TooltipGroup>
).toJSON();
expect(tree).toMatchSnapshot();
});
});
5 changes: 5 additions & 0 deletions src/components/__snapshots__/NavBar.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`NavBar matches snapshot 1`] = `
<div
className="sc-gsnTZi dMcFZD"
role="toolbar"
>
<div
className="sc-dkzDqf bpDzAE"
Expand All @@ -15,6 +16,7 @@ exports[`NavBar matches snapshot 1`] = `
exports[`NavBar sets the maxWidth 1`] = `
<div
className="sc-gsnTZi dMcFZD"
role="toolbar"
>
<div
className="sc-dkzDqf gQjsvL"
Expand All @@ -27,6 +29,7 @@ exports[`NavBar sets the maxWidth 1`] = `
exports[`NavBar with a logo customizes the alt text 1`] = `
<div
className="sc-gsnTZi dMcFZD"
role="toolbar"
>
<div
className="sc-dkzDqf bpDzAE"
Expand Down Expand Up @@ -79,6 +82,7 @@ exports[`NavBar with a logo customizes the alt text 1`] = `
exports[`NavBar with a logo links the logo 1`] = `
<div
className="sc-gsnTZi dMcFZD"
role="toolbar"
>
<div
className="sc-dkzDqf bpDzAE"
Expand Down Expand Up @@ -135,6 +139,7 @@ exports[`NavBar with a logo links the logo 1`] = `
exports[`NavBar with a logo matches snapshot 1`] = `
<div
className="sc-gsnTZi dMcFZD"
role="toolbar"
>
<div
className="sc-dkzDqf bpDzAE"
Expand Down
14 changes: 14 additions & 0 deletions src/components/__snapshots__/Radio.spec.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Radio matches disabled snapshot 1`] = `
<label
aria-disabled={true}
className="sc-hKMtZM fMGZzH"
>
<input
aria-disabled={true}
className="sc-eCYdqJ bstnXk"
type="radio"
/>
Disabled
</label>
`;

exports[`Radio matches snapshot 1`] = `
<label
className="sc-hKMtZM jREXRM"
Expand Down
28 changes: 28 additions & 0 deletions src/components/__snapshots__/Tooltip.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,31 @@ Array [
</div>,
]
`;

exports[`Tooltip uses icon 1`] = `
<button
className="sc-dkzDqf dcHEnX"
data-rac=""
onBlur={[Function]}
onClick={[Function]}
onDragStart={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onMouseDown={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
onMouseUp={[Function]}
onPointerDown={[Function]}
onTouchCancel={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
type="button"
>
<img
alt=""
aria-hidden={true}
src="icon"
/>
</button>
`;
Loading