Skip to content

Commit 3d7a936

Browse files
Datepicker: Lint componentDidUpdate changes
1 parent 2646a0e commit 3d7a936

File tree

3 files changed

+43
-42
lines changed

3 files changed

+43
-42
lines changed

components/date-picker/__examples__/default.jsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import IconSettings from '~/components/icon-settings';
66
import Datepicker from '~/components/date-picker';
77

88
class Example extends React.Component {
9-
static displayName = 'DatepickerExample';
9+
static displayName = 'DatepickerExample';
1010

11-
constructor() {
12-
super();
11+
constructor() {
12+
super();
1313
this.state = {
14-
value: undefined
15-
}
16-
}
17-
18-
handleChange = (event, data) => {
19-
this.setState({value: data.date })
20-
}
14+
value: undefined,
15+
};
16+
}
17+
18+
handleChange = (event, data) => {
19+
this.setState({ value: data.date });
20+
};
2121

2222
render() {
2323
return (
@@ -27,9 +27,9 @@ class Example extends React.Component {
2727
label: 'Date',
2828
}}
2929
onChange={(event, data) => {
30-
this.handleChange(event, data);
30+
this.handleChange(event, data);
3131

32-
if (this.props.action) {
32+
if (this.props.action) {
3333
const dataAsArray = Object.keys(data).map((key) => data[key]);
3434
this.props.action('onChange')(event, data, ...dataAsArray);
3535
} else if (console) {
@@ -49,8 +49,8 @@ class Example extends React.Component {
4949
}}
5050
parser={(dateString) => {
5151
return moment(dateString, 'MM-DD-YYYY').toDate();
52-
}}
53-
value={this.state.value}
52+
}}
53+
value={this.state.value}
5454
/>
5555
</IconSettings>
5656
);

components/date-picker/__tests__/date-picker.browser-test.jsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ describe('SLDSDatepicker', function describeFunction() {
175175
const firstDayOfMonth = wrapper
176176
.find('.datepicker__month [aria-disabled=false]')
177177
.first();
178-
expect(firstDayOfMonth).to.exist;
178+
expect(firstDayOfMonth).to.exist;
179179
firstDayOfMonth.simulate('click', {});
180180
});
181181
}}
@@ -443,15 +443,15 @@ describe('SLDSDatepicker', function describeFunction() {
443443
afterEach(() => wrapper.unmount());
444444

445445
it('disable weekends', (done) => {
446-
// this only tests if onChange fires
447-
const handleChangeSpy = sinon.spy();
448-
wrapper = mount(
446+
// this only tests if onChange fires
447+
const handleChangeSpy = sinon.spy();
448+
wrapper = mount(
449449
<DemoComponent
450450
isOpen
451451
menuPosition="relative"
452452
value={new Date(2007, 0, 5)}
453-
dateDisabled={({ date }) => date.getDay() > 5 || date.getDay() < 1}
454-
onChange={handleChangeSpy}
453+
dateDisabled={({ date }) => date.getDay() > 5 || date.getDay() < 1}
454+
onChange={handleChangeSpy}
455455
/>
456456
);
457457

@@ -468,9 +468,9 @@ describe('SLDSDatepicker', function describeFunction() {
468468
const day = wrapper
469469
.find('.datepicker__month [aria-disabled=false]')
470470
.first();
471-
day.simulate('click', {});
471+
day.simulate('click', {});
472472

473-
expect(handleChangeSpy.calledOnce).to.equal(true);
473+
expect(handleChangeSpy.calledOnce).to.equal(true);
474474
done();
475475

476476
const trigger = wrapper.find(triggerClassSelector);

components/date-picker/date-picker.jsx

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,17 @@ class Datepicker extends React.Component {
275275
}
276276

277277
getDatePicker = ({ labels, assistiveText }) => {
278-
let date;
279-
// Use props if present. Otherwise, use state.
280-
if(this.props.value) {
281-
date = this.props.formatter(this.props.value)
282-
? this.parseDate(this.props.formatter(this.props.value))
283-
: this.props.value;
284-
}
285-
else {
286-
date = this.state.formattedValue
287-
? this.parseDate(this.state.formattedValue)
288-
: this.state.value;
289-
}
278+
let date;
279+
// Use props if present. Otherwise, use state.
280+
if (this.props.value) {
281+
date = this.props.formatter(this.props.value)
282+
? this.parseDate(this.props.formatter(this.props.value))
283+
: this.props.value;
284+
} else {
285+
date = this.state.formattedValue
286+
? this.parseDate(this.state.formattedValue)
287+
: this.state.value;
288+
}
290289

291290
return (
292291
<CalendarWrapper
@@ -412,7 +411,9 @@ class Datepicker extends React.Component {
412411
this.openDialog();
413412
},
414413
onKeyDown: this.handleKeyDown,
415-
value: this.props.value ? this.props.formatter(this.props.value) : this.state.inputValue,
414+
value: this.props.value
415+
? this.props.formatter(this.props.value)
416+
: this.state.inputValue,
416417
};
417418

418419
// eslint-disable react/prop-types
@@ -460,13 +461,13 @@ class Datepicker extends React.Component {
460461
};
461462

462463
handleCalendarChange = (event, { date }) => {
463-
if(!this.props.value) {
464-
this.setState({
465-
value: date,
466-
formattedValue: this.props.formatter(date),
467-
inputValue: this.props.formatter(date),
468-
});
469-
}
464+
if (!this.props.value) {
465+
this.setState({
466+
value: date,
467+
formattedValue: this.props.formatter(date),
468+
inputValue: this.props.formatter(date),
469+
});
470+
}
470471

471472
this.handleRequestClose();
472473

0 commit comments

Comments
 (0)