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

Commit ce61269

Browse files
Fix merge conflicts in PR-201 (#383)
* 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
1 parent 27d2309 commit ce61269

File tree

6 files changed

+95
-18
lines changed

6 files changed

+95
-18
lines changed

CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5-
## [0.38.1] - 2018-11-21
5+
## [0.38.1] - 2018-11-14
66
### Fixed
7+
- The issue [#115](https://github.com/plotly/dash-core-components/issues/115)
8+
with datepicker, which didn't appear when the date value is `None` was fixed.
9+
By default, current month would appear in such cases for
10+
`DatePickerRange` and `DatePickerSingle` components.
11+
See pull request https://github.com/plotly/dash-core-components/pull/201.
712
- Refactored the way the Graph component would generate an unique id if none provided.
813
- 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)
914

dash_core_components/dash_core_components.dev.js

+2-2
Large diffs are not rendered by default.

dash_core_components/dash_core_components.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/DatePickerRange.react.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ export default class DatePickerRange extends Component {
145145
initialVisibleMonth={() => {
146146
if (initial_visible_month) {
147147
return initial_visible_month;
148-
}
149-
if (focusedInput === 'endDate') {
148+
} else if (end_date && focusedInput === 'endDate') {
150149
return end_date;
150+
} else if (start_date && focusedInput === 'startDate') {
151+
return start_date;
151152
}
152153
return start_date;
153154
}}

src/components/DatePickerSingle.react.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ export default class DatePickerSingle extends Component {
110110
onDateChange={this.onDateChange}
111111
focused={focused}
112112
onFocusChange={({focused}) => this.setState({focused})}
113-
initialVisibleMonth={() => date || initial_visible_month}
113+
initialVisibleMonth={() =>
114+
date || initial_visible_month || moment()
115+
}
114116
isOutsideRange={this.isOutsideRange}
115117
numberOfMonths={number_of_months_shown}
116118
withPortal={with_portal && verticalFlag}

test/test_integration.py

+80-11
Original file line numberDiff line numberDiff line change
@@ -341,18 +341,51 @@ def test_gallery(self):
341341
}
342342
),
343343

344-
html.Label('DatePickerSingle'),
345-
dcc.DatePickerSingle(
346-
id='date-picker-single',
347-
date=datetime(1997, 5, 10)
348-
),
344+
html.Div([
345+
html.Label('DatePickerSingle'),
346+
dcc.DatePickerSingle(
347+
id='date-picker-single',
348+
date=datetime(1997, 5, 10)
349+
),
350+
html.Div([
351+
html.Label('DatePickerSingle - empty input'),
352+
dcc.DatePickerSingle(),
353+
], id='dt-single-no-date-value'
354+
),
355+
html.Div([
356+
html.Label('DatePickerSingle - initial visible month (May 97)'),
357+
dcc.DatePickerSingle(
358+
initial_visible_month=datetime(1997, 5, 10)
359+
),
360+
], id='dt-single-no-date-value-init-month'
361+
),
362+
]),
349363

350-
html.Label('DatePickerRange'),
351-
dcc.DatePickerRange(
352-
id='date-picker-range',
353-
start_date=datetime(1997, 5, 3),
354-
end_date_placeholder_text='Select a date!'
355-
),
364+
html.Div([
365+
html.Label('DatePickerRange'),
366+
dcc.DatePickerRange(
367+
id='date-picker-range',
368+
start_date=datetime(1997, 5, 3),
369+
end_date_placeholder_text='Select a date!'
370+
),
371+
html.Div([
372+
html.Label('DatePickerRange - empty input'),
373+
dcc.DatePickerRange(
374+
start_date_placeholder_text='Start date',
375+
end_date_placeholder_text='End date'
376+
),
377+
], id='dt-range-no-date-values'
378+
),
379+
html.Div([
380+
html.Label('DatePickerRange - initial visible month (May 97)'),
381+
dcc.DatePickerRange(
382+
start_date_placeholder_text='Start date',
383+
end_date_placeholder_text='End date',
384+
initial_visible_month=datetime(1997, 5, 10)
385+
),
386+
], id='dt-range-no-date-values-init-month'
387+
),
388+
]),
356389

357390
html.Label('TextArea'),
358391
dcc.Textarea(
@@ -411,6 +444,42 @@ def test_gallery(self):
411444

412445
self.snapshot('gallery - text input')
413446

447+
# DatePickerSingle and DatePickerRange test
448+
# for issue with datepicker when date value is `None`
449+
dt_input_1 = self.driver.find_element_by_css_selector(
450+
'#dt-single-no-date-value #date'
451+
)
452+
dt_input_1.click()
453+
self.snapshot('gallery - DatePickerSingle\'s datepicker '
454+
'when no date value and no initial month specified')
455+
dt_input_1.send_keys("1997-05-03")
456+
457+
dt_input_2 = self.driver.find_element_by_css_selector(
458+
'#dt-single-no-date-value-init-month #date'
459+
)
460+
dt_input_2.click()
461+
self.snapshot('gallery - DatePickerSingle\'s datepicker '
462+
'when no date value, but initial month is specified')
463+
dt_input_2.send_keys("1997-05-03")
464+
465+
dt_input_3 = self.driver.find_element_by_css_selector(
466+
'#dt-range-no-date-values #endDate'
467+
)
468+
dt_input_3.click()
469+
self.snapshot('gallery - DatePickerRange\'s datepicker '
470+
'when neither start date nor end date '
471+
'nor initial month is specified')
472+
dt_input_3.send_keys("1997-05-03")
473+
474+
dt_input_4 = self.driver.find_element_by_css_selector(
475+
'#dt-range-no-date-values-init-month #endDate'
476+
)
477+
dt_input_4.click()
478+
self.snapshot('gallery - DatePickerRange\'s datepicker '
479+
'when neither start date nor end date is specified, '
480+
'but initial month is')
481+
dt_input_4.send_keys("1997-05-03")
482+
414483
def test_tabs_without_children(self):
415484
app = dash.Dash(__name__)
416485

0 commit comments

Comments
 (0)