Skip to content

Commit

Permalink
fix(limel-date-picker): keep formatted value in sync
Browse files Browse the repository at this point in the history
fix #295
  • Loading branch information
BregenzerK authored and adrianschmidt committed Sep 10, 2019
1 parent 4330f94 commit 237ebd6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/components/date-picker/date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
EventEmitter,
Listen,
Prop,
State,
} from '@stencil/core';

import { Translations } from '../../global/translations';
Expand Down Expand Up @@ -89,11 +90,18 @@ export class DatePicker {
@Event()
private change: EventEmitter;

@State()
private formattedValue: string;

private picker: Picker;

private container: HTMLElement;
private input: HTMLElement;

constructor() {
this.handleChange = this.handleChange.bind(this);
}

public componentWillLoad() {
switch (this.type) {
case 'date':
Expand Down Expand Up @@ -165,23 +173,22 @@ export class DatePicker {
this.container = this.host.shadowRoot.querySelector('.container');

this.picker.init(this.input, this.container, this.value);
this.formattedValue = this.picker.formatDate(this.value);
}

public componentDidUnload() {
this.picker.destroy();
}

public render() {
const formattedValue = this.picker.formatDate(this.value);

return (
<div class="container">
<limel-input-field
disabled={this.disabled}
invalid={this.invalid}
label={this.label}
required={this.required}
value={formattedValue}
value={this.formattedValue}
onChange={this.handleChange}
/>
</div>
Expand All @@ -195,5 +202,6 @@ export class DatePicker {

private handleChange(event) {
event.stopPropagation();
this.formattedValue = event.detail;
}
}

0 comments on commit 237ebd6

Please sign in to comment.