Skip to content

Commit

Permalink
fix(limel-date-picker): don't format value for native pickers
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianschmidt committed Sep 10, 2019
1 parent 88aa280 commit 6e944ed
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/components/date-picker/date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ export class DatePicker {
'limel-input-field'
);
this.input = textfield.shadowRoot.querySelector('input');
const container: HTMLElement = this.host.shadowRoot.querySelector('.container');
const container: HTMLElement = this.host.shadowRoot.querySelector(
'.container'
);

this.picker.init(this.input, container, this.value);
this.formattedValue = this.picker.formatDate(this.value);
Expand Down
4 changes: 4 additions & 0 deletions src/components/date-picker/pickers/Picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export abstract class Picker {
): flatpickr.Options.Options;

public formatDate(date: Date) {
if (this.nativePicker) {
return date ? JSON.stringify(date) : '';
}
if (date) {
return moment(date)
.locale(this.getMomentLang())
Expand Down Expand Up @@ -128,6 +131,7 @@ export abstract class Picker {
pickerDate = momentInputDate.toDate();
this.flatpickr.setDate(pickerDate);
} else {
pickerDate = null;
this.flatpickr.clear();
}
}
Expand Down
18 changes: 10 additions & 8 deletions src/examples/date-picker/date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ const types = ['datetime', 'date', 'time', 'week', 'month', 'quarter', 'year'];
})
export class DatePickerExample {
@State()
private datetime = new Date('2018-12-25 16:00');
private datetime = new Date();

@State()
private date = new Date('2018-12-25');
private date = new Date();

@State()
private time = new Date('2018-12-25 16:00');
private time = new Date();

@State()
private week = new Date('2018-12-24');
private week = new Date();

@State()
private month = new Date('2018-12-01');
private month = new Date();

@State()
private quarter = new Date('2018-10-01');
private quarter = new Date();

@State()
private year = new Date('2018-10-01');
private year = new Date();

public render() {
return types.map((type: DateType) => {
Expand All @@ -44,7 +44,9 @@ export class DatePickerExample {
<p style={{ 'font-size': 'small' }}>
Value:{' '}
<code>
{this[type] ? this[type].toString() : 'invalid'}
{this[type]
? this[type].toString()
: JSON.stringify(this[type])}
</code>
</p>
</p>
Expand Down

0 comments on commit 6e944ed

Please sign in to comment.