Skip to content

Commit

Permalink
feat(Timeline): Remove unwanted sidebar labels
Browse files Browse the repository at this point in the history
Add aria-label alternative where Months, Weeks, Days are not displayed.
  • Loading branch information
m7kvqbe1 committed Oct 6, 2020
1 parent c7a4ab1 commit 593dd0c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ const StyledTimelineHeaderRow = styled<any>(TimelineRow)`
`}
`

export const TimelineHeaderRow: React.FC<TimelineHeaderRowProps> = (props) => (
<StyledTimelineHeaderRow isHeader {...props} />
)
export const TimelineHeaderRow: React.FC<TimelineHeaderRowProps> = ({
name,
...rest
}) => <StyledTimelineHeaderRow isHeader ariaLabel={name} {...rest} />

TimelineHeaderRow.displayName = 'TimelineHeaderRow'
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const TimelineMonths: React.FC<TimelineMonthsProps> = ({ render }) => (
className="timeline__months"
data-testid="timeline-months"
name="Months"
renderRowHeader={(name) => (
renderRowHeader={() => (
<>
<StyledNavigation
className="timeline__navigation"
Expand All @@ -90,7 +90,6 @@ export const TimelineMonths: React.FC<TimelineMonthsProps> = ({ render }) => (
data-testid="timeline-side-button-right"
/>
</StyledNavigation>
{name}
</>
)}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface TimelineRowProps extends ComponentWithClass {
| React.ReactElement<TimelineEventsProps>
| React.ReactElement<TimelineEventsProps>[]
name?: string
ariaLabel?: string
renderRowHeader?: (name: string) => React.ReactElement
isHeader?: boolean
}
Expand Down Expand Up @@ -58,6 +59,7 @@ const StyledRowContent = styled.div`
export const TimelineRow: React.FC<TimelineRowProps> = ({
children,
name,
ariaLabel,
renderRowHeader,
isHeader,
className,
Expand All @@ -79,6 +81,7 @@ export const TimelineRow: React.FC<TimelineRowProps> = ({
isHeader={isHeader}
data-testid="timeline-row-header"
role="rowheader"
aria-label={ariaLabel || name}
>
{renderRowHeader ? renderRowHeader(name) : name}
</StyledRowHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ describe('Timeline', () => {
})

it('should set the `role` attribute to `row` on the no data message', () => {
expect(wrapper.queryByTestId('timeline-no-data')).toHaveAttribute('role', 'row')
expect(wrapper.queryByTestId('timeline-no-data')).toHaveAttribute(
'role',
'row'
)
})

it('should set the `role` attribute to `cell` on the no data message text', () => {
Expand Down Expand Up @@ -321,12 +324,12 @@ describe('Timeline', () => {
)
})

it('should render the row headers', () => {
it('should apply `aria-label` for row headers', () => {
const rowHeaders = wrapper.getAllByTestId('timeline-row-header')

expect(rowHeaders[0]).toHaveTextContent('Months')
expect(rowHeaders[1]).toHaveTextContent('Weeks')
expect(rowHeaders[2]).toHaveTextContent('Days')
expect(rowHeaders[0]).toHaveAttribute('aria-label', 'Months')
expect(rowHeaders[1]).toHaveAttribute('aria-label', 'Weeks')
expect(rowHeaders[2]).toHaveAttribute('aria-label', 'Days')
})
})

Expand Down Expand Up @@ -383,22 +386,17 @@ describe('Timeline', () => {
it('should render the row headers', () => {
const rowHeaders = wrapper.getAllByTestId('timeline-row-header')

expect(rowHeaders[0]).toHaveTextContent('Months')
expect(rowHeaders[1]).toHaveTextContent('Weeks')
expect(rowHeaders[2]).toHaveTextContent('Days')
expect(rowHeaders[3]).toHaveTextContent('Row 1')
expect(rowHeaders[4]).toHaveTextContent('Row 2')
})

it('should set the `aria-label` attributes for the timeline navigation buttons', () => {
expect(wrapper.getByTestId('timeline-side-button-left')).toHaveAttribute(
'aria-label',
'Navigate left'
)
expect(wrapper.getByTestId('timeline-side-button-right')).toHaveAttribute(
'aria-label',
'Navigate right'
)
expect(
wrapper.getByTestId('timeline-side-button-left')
).toHaveAttribute('aria-label', 'Navigate left')
expect(
wrapper.getByTestId('timeline-side-button-right')
).toHaveAttribute('aria-label', 'Navigate right')
})

describe('and when the left button is clicked', () => {
Expand Down Expand Up @@ -471,12 +469,12 @@ describe('Timeline', () => {
)
})

it('should render the row headers', () => {
it('should apply `aria-label` for row headers', () => {
const rowHeaders = wrapper.getAllByTestId('timeline-row-header')

expect(rowHeaders[0]).toHaveTextContent('Months')
expect(rowHeaders[1]).toHaveTextContent('Weeks')
expect(rowHeaders[2]).toHaveTextContent('Days')
expect(rowHeaders[0]).toHaveAttribute('aria-label', 'Months')
expect(rowHeaders[1]).toHaveAttribute('aria-label', 'Weeks')
expect(rowHeaders[2]).toHaveAttribute('aria-label', 'Days')
})
})

Expand Down Expand Up @@ -1288,9 +1286,7 @@ describe('Timeline', () => {
})

it('should render the arbitrary content', () => {
expect(
wrapper.getByText('Arbitrary event content')
).toBeInTheDocument()
expect(wrapper.getByText('Arbitrary event content')).toBeInTheDocument()
})

it('should set the `aria-label` on the event', () => {
Expand Down

0 comments on commit 593dd0c

Please sign in to comment.