Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
Fix merge conflicts in PR-201 (#383)
Browse files Browse the repository at this point in the history
* Fix for datepicker initial month

Added current date as the last resort for the initialVisibleMonth property of the component in DatePickerRange.react.js and in DatePickerSingle.react.js (issue #115)

* Fix formatting

* Fix DatePickerSingle formatting
  • Loading branch information
valentijnnieman committed Nov 21, 2018
1 parent 27d2309 commit ce61269
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 18 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.38.1] - 2018-11-21
## [0.38.1] - 2018-11-14
### Fixed
- The issue [#115](https://github.com/plotly/dash-core-components/issues/115)
with datepicker, which didn't appear when the date value is `None` was fixed.
By default, current month would appear in such cases for
`DatePickerRange` and `DatePickerSingle` components.
See pull request https://github.com/plotly/dash-core-components/pull/201.
- Refactored the way the Graph component would generate an unique id if none provided.
- Default CSS imported via `style-loader` is now placed at top, so that user supplied CSS can overwrite it, fixes [#380](https://github.com/plotly/dash-core-components/issues/380)

Expand Down
4 changes: 2 additions & 2 deletions dash_core_components/dash_core_components.dev.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dash_core_components/dash_core_components.min.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/components/DatePickerRange.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@ export default class DatePickerRange extends Component {
initialVisibleMonth={() => {
if (initial_visible_month) {
return initial_visible_month;
}
if (focusedInput === 'endDate') {
} else if (end_date && focusedInput === 'endDate') {
return end_date;
} else if (start_date && focusedInput === 'startDate') {
return start_date;
}
return start_date;
}}
Expand Down
4 changes: 3 additions & 1 deletion src/components/DatePickerSingle.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ export default class DatePickerSingle extends Component {
onDateChange={this.onDateChange}
focused={focused}
onFocusChange={({focused}) => this.setState({focused})}
initialVisibleMonth={() => date || initial_visible_month}
initialVisibleMonth={() =>
date || initial_visible_month || moment()
}
isOutsideRange={this.isOutsideRange}
numberOfMonths={number_of_months_shown}
withPortal={with_portal && verticalFlag}
Expand Down
91 changes: 80 additions & 11 deletions test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,18 +341,51 @@ def test_gallery(self):
}
),

html.Label('DatePickerSingle'),
dcc.DatePickerSingle(
id='date-picker-single',
date=datetime(1997, 5, 10)
),
html.Div([
html.Label('DatePickerSingle'),
dcc.DatePickerSingle(
id='date-picker-single',
date=datetime(1997, 5, 10)
),
html.Div([
html.Label('DatePickerSingle - empty input'),
dcc.DatePickerSingle(),
], id='dt-single-no-date-value'
),
html.Div([
html.Label('DatePickerSingle - initial visible month (May 97)'),
dcc.DatePickerSingle(
initial_visible_month=datetime(1997, 5, 10)
),
], id='dt-single-no-date-value-init-month'
),
]),

html.Label('DatePickerRange'),
dcc.DatePickerRange(
id='date-picker-range',
start_date=datetime(1997, 5, 3),
end_date_placeholder_text='Select a date!'
),
html.Div([
html.Label('DatePickerRange'),
dcc.DatePickerRange(
id='date-picker-range',
start_date=datetime(1997, 5, 3),
end_date_placeholder_text='Select a date!'
),
html.Div([
html.Label('DatePickerRange - empty input'),
dcc.DatePickerRange(
start_date_placeholder_text='Start date',
end_date_placeholder_text='End date'
),
], id='dt-range-no-date-values'
),
html.Div([
html.Label('DatePickerRange - initial visible month (May 97)'),
dcc.DatePickerRange(
start_date_placeholder_text='Start date',
end_date_placeholder_text='End date',
initial_visible_month=datetime(1997, 5, 10)
),
], id='dt-range-no-date-values-init-month'
),
]),

html.Label('TextArea'),
dcc.Textarea(
Expand Down Expand Up @@ -411,6 +444,42 @@ def test_gallery(self):

self.snapshot('gallery - text input')

# DatePickerSingle and DatePickerRange test
# for issue with datepicker when date value is `None`
dt_input_1 = self.driver.find_element_by_css_selector(
'#dt-single-no-date-value #date'
)
dt_input_1.click()
self.snapshot('gallery - DatePickerSingle\'s datepicker '
'when no date value and no initial month specified')
dt_input_1.send_keys("1997-05-03")

dt_input_2 = self.driver.find_element_by_css_selector(
'#dt-single-no-date-value-init-month #date'
)
dt_input_2.click()
self.snapshot('gallery - DatePickerSingle\'s datepicker '
'when no date value, but initial month is specified')
dt_input_2.send_keys("1997-05-03")

dt_input_3 = self.driver.find_element_by_css_selector(
'#dt-range-no-date-values #endDate'
)
dt_input_3.click()
self.snapshot('gallery - DatePickerRange\'s datepicker '
'when neither start date nor end date '
'nor initial month is specified')
dt_input_3.send_keys("1997-05-03")

dt_input_4 = self.driver.find_element_by_css_selector(
'#dt-range-no-date-values-init-month #endDate'
)
dt_input_4.click()
self.snapshot('gallery - DatePickerRange\'s datepicker '
'when neither start date nor end date is specified, '
'but initial month is')
dt_input_4.send_keys("1997-05-03")

def test_tabs_without_children(self):
app = dash.Dash(__name__)

Expand Down

0 comments on commit ce61269

Please sign in to comment.