Skip to content

Commit

Permalink
fix(timepicker): when showMeridian changes value, time is rerendered
Browse files Browse the repository at this point in the history
fixes #2476
  • Loading branch information
valorkin committed Aug 23, 2017
1 parent 646e033 commit e59172f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
17 changes: 12 additions & 5 deletions src/timepicker/reducer/timepicker.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export class TimepickerState {
controls: TimepickerControls;
}

export const initialState = {
export const initialState: TimepickerState = {
value: null,
config: new TimepickerConfig(),
controls: {
canIncrementHours: true,
Expand All @@ -28,7 +29,7 @@ export const initialState = {
canDecrementMinutes: true,
canDecrementSeconds: true
}
} as TimepickerState;
};

export function timepickerReducer(state = initialState, action: Action) {
switch (action.type) {
Expand Down Expand Up @@ -81,11 +82,17 @@ export function timepickerReducer(state = initialState, action: Action) {

case (TimepickerActions.UPDATE_CONTROLS): {
const _newControlsState = timepickerControls(state.value, action.payload);

return Object.assign({}, state, {
const _newState: TimepickerState = {
value: state.value,
config: action.payload,
controls: _newControlsState
});
};

if (state.config.showMeridian !== _newState.config.showMeridian) {
_newState.value = new Date(state.value);
}

return Object.assign({}, state, _newState);
}

default:
Expand Down
14 changes: 6 additions & 8 deletions src/timepicker/timepicker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,16 @@ export const TIMEPICKER_CONTROL_VALUE_ACCESSOR: any = {
<!-- increment hours button-->
<td>
<a class="btn btn-link" [class.disabled]="!canIncrementHours"
(click)="changeHours(hourStep)">
<span class="glyphicon glyphicon-chevron-up"></span>
</a>
(click)="changeHours(hourStep)"
><span class="glyphicon glyphicon-chevron-up"></span></a>
</td>
<!-- divider -->
<td>&nbsp;&nbsp;&nbsp;</td>
<!-- increment minutes button -->
<td>
<a class="btn btn-link" [class.disabled]="!canIncrementMinutes"
(click)="changeMinutes(minuteStep)">
<span class="glyphicon glyphicon-chevron-up"></span>
</a>
(click)="changeMinutes(minuteStep)"
><span class="glyphicon glyphicon-chevron-up"></span></a>
</td>
<!-- divider -->
<td *ngIf="showSeconds">&nbsp;</td>
Expand Down Expand Up @@ -112,8 +110,8 @@ export const TIMEPICKER_CONTROL_VALUE_ACCESSOR: any = {
<button type="button" class="btn btn-default text-center"
[disabled]="readonlyInput"
[class.disabled]="readonlyInput"
(click)="toggleMeridian()">
{{meridian}}
(click)="toggleMeridian()"
>{{ meridian }}
</button>
</td>
</tr>
Expand Down

0 comments on commit e59172f

Please sign in to comment.