Skip to content

Commit 716ab8f

Browse files
authored
Undefined classnames in TimelineHeaders (#586)
Undefined classnames in TimelineHeaders
2 parents f20b16d + 270cdec commit 716ab8f

File tree

4 files changed

+48
-22
lines changed

4 files changed

+48
-22
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres (more or less) to [Semantic Versioning](http://semver.o
77

88
## Unreleased
99

10+
## 0.25.3
11+
12+
- Fixed the `undefined` classnames in TimelineHeaders #566 @trevdor
13+
1014
## 0.25.2
1115

1216
- Fixed the auto-scroll right bug in a scaled browser. #528 @cw196

__tests__/components/Headers/TimelineHeader.test.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,27 @@ describe('TimelineHeader', () => {
6868
expect(getByTestId('headerContainer')).toHaveClass('testClassName')
6969
})
7070

71+
it('Given TimelineHeader When no calendarHeaderClassName specified Then undefined should not be applied to the date header container', () => {
72+
const { getByTestId } = renderTimelineWithLeftAndRightSidebar({
73+
calendarHeaderClassName: undefined
74+
})
75+
expect(getByTestId('headerContainer')).not.toHaveClass('undefined')
76+
})
77+
7178
it('Given TimelineHeader When pass className Then it should be applied to the root header container', () => {
7279
const { getByTestId } = renderTimelineWithLeftAndRightSidebar({
7380
className: 'testClassName'
7481
})
7582
expect(getByTestId('headerRootDiv')).toHaveClass('testClassName')
7683
})
7784

85+
it('Given TimelineHeader When no className specified Then undefined should not be applied to the root header container', () => {
86+
const { getByTestId } = renderTimelineWithLeftAndRightSidebar({
87+
className: undefined
88+
})
89+
expect(getByTestId('headerRootDiv')).not.toHaveClass('undefined')
90+
})
91+
7892
it('Given TimelineHeader When rendered Then it should render the default styles of the date header container', () => {
7993
const { getByTestId } = renderTimelineWithLeftAndRightSidebar()
8094
const headerContainer = getByTestId('headerContainer')
@@ -116,15 +130,16 @@ describe('TimelineHeader', () => {
116130
expect(getAllByTestId('sidebarHeader')).toHaveLength(1)
117131
})
118132
it('Given SidebarHeader When passing variant prop with right value Then it should rendered above the right sidebar', () => {
119-
const { getByTestId, getAllByTestId, debug } = renderSidebarHeaderWithCustomValues(
120-
{ variant: 'right' }
121-
)
133+
const {
134+
getByTestId,
135+
getAllByTestId,
136+
debug
137+
} = renderSidebarHeaderWithCustomValues({ variant: 'right' })
122138
expect(getByTestId('sidebarHeader')).toBeInTheDocument()
123139
expect(getAllByTestId('sidebarHeader')).toHaveLength(2)
124-
expect(getAllByTestId('sidebarHeader')[1].previousElementSibling).toHaveAttribute(
125-
'data-testid',
126-
'headerContainer'
127-
)
140+
expect(
141+
getAllByTestId('sidebarHeader')[1].previousElementSibling
142+
).toHaveAttribute('data-testid', 'headerContainer')
128143
})
129144

130145
it('Given SidebarHeader When passing variant prop with unusual value Then it should rendered above the left sidebar by default', () => {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-calendar-timeline",
3-
"version": "0.25.1",
3+
"version": "0.25.2",
44
"description": "react calendar timeline",
55
"main": "lib/index.js",
66
"scripts": {
@@ -112,6 +112,7 @@
112112
"babel-plugin-transform-object-rest-spread": "^6.26.0",
113113
"babel-preset-env": "1.7.0",
114114
"babel-preset-react": "^6.5.0",
115+
"classnames": "^2.2.6",
115116
"cross-env": "^5.1.4",
116117
"css-loader": "~0.26.0",
117118
"enzyme": "^3.3.0",

src/lib/headers/TimelineHeaders.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import React from 'react'
2+
import classNames from 'classnames'
23
import { TimelineHeadersConsumer } from './HeadersContext'
34
import PropTypes from 'prop-types'
45
import SidebarHeader from './SidebarHeader'
5-
import { RIGHT_VARIANT, LEFT_VARIANT } from './constants'
6+
import { RIGHT_VARIANT } from './constants'
67
class TimelineHeaders extends React.Component {
78
static propTypes = {
89
registerScroll: PropTypes.func.isRequired,
910
leftSidebarWidth: PropTypes.number.isRequired,
1011
rightSidebarWidth: PropTypes.number.isRequired,
1112
style: PropTypes.object,
13+
children: PropTypes.node,
1214
className: PropTypes.string,
1315
calendarHeaderStyle: PropTypes.object,
1416
calendarHeaderClassName: PropTypes.string,
15-
headerRef: PropTypes.func,
17+
headerRef: PropTypes.func
1618
}
1719

1820
constructor(props) {
@@ -40,8 +42,8 @@ class TimelineHeaders extends React.Component {
4042
}
4143
}
4244

43-
handleRootRef = (element) => {
44-
if(this.props.headerRef){
45+
handleRootRef = element => {
46+
if (this.props.headerRef) {
4547
this.props.headerRef(element)
4648
}
4749
}
@@ -64,24 +66,27 @@ class TimelineHeaders extends React.Component {
6466
calendarHeaders.push(child)
6567
}
6668
})
67-
if(!leftSidebarHeader){
68-
leftSidebarHeader= <SidebarHeader/>
69+
if (!leftSidebarHeader) {
70+
leftSidebarHeader = <SidebarHeader />
6971
}
70-
if(!rightSidebarHeader && this.props.rightSidebarWidth){
71-
rightSidebarHeader = <SidebarHeader variant="right"/>
72+
if (!rightSidebarHeader && this.props.rightSidebarWidth) {
73+
rightSidebarHeader = <SidebarHeader variant="right" />
7274
}
7375
return (
7476
<div
7577
ref={this.handleRootRef}
7678
data-testid="headerRootDiv"
7779
style={this.getRootStyle()}
78-
className={`rct-header-root ${this.props.className}`}
80+
className={classNames('rct-header-root', this.props.className)}
7981
>
8082
{leftSidebarHeader}
8183
<div
8284
ref={this.props.registerScroll}
8385
style={this.getCalendarHeaderStyle()}
84-
className={`rct-calendar-header ${this.props.calendarHeaderClassName}`}
86+
className={classNames(
87+
'rct-calendar-header',
88+
this.props.calendarHeaderClassName
89+
)}
8590
data-testid="headerContainer"
8691
>
8792
{calendarHeaders}
@@ -106,23 +111,24 @@ const TimelineHeadersWrapper = ({
106111
leftSidebarWidth={leftSidebarWidth}
107112
rightSidebarWidth={rightSidebarWidth}
108113
registerScroll={registerScroll}
109-
children={children}
110114
style={style}
111115
className={className}
112116
calendarHeaderStyle={calendarHeaderStyle}
113117
calendarHeaderClassName={calendarHeaderClassName}
114-
/>
118+
>
119+
{children}
120+
</TimelineHeaders>
115121
)
116122
}}
117123
</TimelineHeadersConsumer>
118124
)
119125

120126
TimelineHeadersWrapper.propTypes = {
121127
style: PropTypes.object,
128+
children: PropTypes.node,
122129
className: PropTypes.string,
123130
calendarHeaderStyle: PropTypes.object,
124-
calendarHeaderClassName: PropTypes.string,
125-
headerRef: PropTypes.func,
131+
calendarHeaderClassName: PropTypes.string
126132
}
127133

128134
export default TimelineHeadersWrapper

0 commit comments

Comments
 (0)