Skip to content

Commit da0fe4d

Browse files
authored
adding option (as default true) to close picker on enter - resolves 438 (#485)
* adding option (as default true) to close picker on enter - resolves 438 * adding changelog
1 parent cd86edb commit da0fe4d

24 files changed

Lines changed: 101 additions & 29 deletions

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file.
33
<a name="8.0.0"></a>
44
# [8.1.0] (???)
55

6+
### Features
7+
- Close popup on enter ([???](https://github.com/vlio20/angular-datepicker/commit/???)) closes [#438](https://github.com/vlio20/angular-datepicker/issues/438)
8+
69
### Bug Fixes
710
- Add debounce on open delay ([???](https://github.com/vlio20/angular-datepicker/commit/???)) closes [#480](https://github.com/vlio20/angular-datepicker/issues/480)
811

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ Here are the available configurations:
115115
| inputElementContainer | `string\|HTMLElement` | `undefined` | All | Will place picker popup relative to the provided elemenr (if string provided will used as a selector) |
116116
| showGoToCurrent | `boolean` | `true` | All | Show/Hides the go to current button on the calendars navigation |
117117
| hideOnOutsideClick | `boolean` | `true` | All | Show/Hides the picker popup after click outside of the component |
118+
| closeOnEnter | `boolean` | `true` | All | Hides the picker popup after enter button keypress |
118119

119120
### API:
120121
In order to use the date-picker api user the `@ViewChild` annotation in the date-picker containing component class, take at the example below:

e2e/app.po.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ export class DemoPage {
9898
hideInputRadio = $('#hideInputRadio');
9999

100100
showOnOutsideClick = $('#showOnOutsideClick');
101-
hideOnOutsideClick = $('#hideOnOutsideClick');
101+
enableCloseOnEnter = $('#enableCloseOnEnter');
102+
disableCloseOnEnter = $('#disableCloseOnEnter');
102103

103104
hourUpBtn = $(`${this.popupSelector} .dp-time-select-control-hours > .dp-time-select-control-up`);
104105
hourDownBtn = $(`${this.popupSelector} .dp-time-select-control-hours > .dp-time-select-control-down`);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {DemoPage} from '../app.po';
2+
import {protractor} from 'protractor';
3+
4+
describe('enter keypress', () => {
5+
let page: DemoPage;
6+
7+
beforeEach(async () => {
8+
page = new DemoPage();
9+
await page.navigateTo();
10+
await page.daytimePickerMenu.click();
11+
});
12+
13+
it('should close the picker on enter keypress', async () => {
14+
await page.dayPickerInput.click();
15+
expect(await page.datePickerPopup.isDisplayed()).toBe(true);
16+
page.dayPickerInput.sendKeys(protractor.Key.ENTER);
17+
expect(await page.datePickerPopup.isDisplayed()).toBe(false);
18+
19+
await page.disableCloseOnEnter.click();
20+
await page.dayPickerInput.click();
21+
expect(await page.datePickerPopup.isDisplayed()).toBe(true);
22+
page.dayPickerInput.sendKeys(protractor.Key.ENTER);
23+
expect(await page.datePickerPopup.isDisplayed()).toBe(true);
24+
});
25+
});

src/demo/demo/date-pickers/common/conts/consts.ts renamed to src/demo/demo/common/conts/consts.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ECalendarValue, IDatePickerConfig} from '../../../../../lib';
1+
import {ECalendarValue, IDatePickerConfig} from '../../../../lib';
22
import * as moment from 'moment';
33

44
export const DEF_CONF: IDatePickerConfig = {
@@ -11,6 +11,7 @@ export const DEF_CONF: IDatePickerConfig = {
1111
openOnFocus: true,
1212
openOnClick: true,
1313
onOpenDelay: 0,
14+
closeOnEnter: true,
1415
weekDayFormat: 'ddd',
1516
appendTo: document.body,
1617
showNearMonthDays: true,

src/demo/demo/date-pickers/common/date-component.component.ts renamed to src/demo/demo/common/date-component.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {INavEvent} from '../../../../lib/common/models/navigation-event.model';
1+
import {INavEvent} from '../../../lib/common/models/navigation-event.model';
22
import * as moment from 'moment';
33
import {Moment} from 'moment';
4-
import {DatePickerComponent, DatePickerDirective, ISelectionEvent} from '../../../../lib';
4+
import {DatePickerComponent, DatePickerDirective, ISelectionEvent} from '../../../lib';
55
import {ViewChild} from '@angular/core';
66
import {FormControl, ValidatorFn, Validators} from '@angular/forms';
77

src/demo/demo/config-form/config-form.component.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,28 @@ <h3 class="dp-options-section">Config options</h3>
797797
</select>
798798
</div>
799799
</div>
800+
801+
<div *ngIf="isValidConfig('closeOnEnter')" class="dp-option">
802+
<span class="dp-option-header">
803+
Close On Enter (closeOnEnter):
804+
</span>
805+
<div class="dp-option-playground">
806+
<label>Enabled
807+
<input id="enableCloseOnEnter"
808+
[formControl]="closeOnEnter"
809+
[value]="true"
810+
name="closeOnEnter"
811+
type="radio">
812+
</label>
813+
<label>Disabled
814+
<input id="disableCloseOnEnter"
815+
[formControl]="closeOnEnter"
816+
[value]="false"
817+
name="closeOnEnter"
818+
type="radio">
819+
</label>
820+
</div>
821+
</div>
800822
</div>
801823

802824
<div class="dp-api">

src/demo/demo/config-form/config-form.component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const PICKER_OPTION_KEYS = [
2525
'placeholder',
2626
'required',
2727
'hideInputContainer',
28-
'hideOnOutsideClick'
28+
'hideOnOutsideClick',
29+
'closeOnEnter'
2930
];
3031
const DAY_PICKER_DIRECTIVE_OPTION_KEYS = [
3132
'allowMultiSelect',
@@ -219,6 +220,7 @@ export class ConfigFormComponent implements OnInit {
219220
showMultipleYearsNavigation: FormControl;
220221
multipleYearsNavigateBy: FormControl;
221222
returnedValueType: FormControl;
223+
closeOnEnter: FormControl;
222224

223225
ngOnInit() {
224226
this.localFormat = this.getDefaultFormatByMode(this.pickerMode);
@@ -264,6 +266,7 @@ export class ConfigFormComponent implements OnInit {
264266
this.showMultipleYearsNavigation = new FormControl(this.config.showMultipleYearsNavigation);
265267
this.multipleYearsNavigateBy = new FormControl(this.config.multipleYearsNavigateBy);
266268
this.returnedValueType = new FormControl(this.config.returnedValueType);
269+
this.closeOnEnter = new FormControl(this.config.closeOnEnter);
267270
this.initListeners();
268271
}
269272

@@ -609,6 +612,12 @@ export class ConfigFormComponent implements OnInit {
609612
returnedValueType: val
610613
});
611614
});
615+
616+
this.closeOnEnter.valueChanges.subscribe((val) => {
617+
this.onConfigChange.emit({
618+
closeOnEnter: val
619+
});
620+
});
612621
}
613622

614623
private getDefaultFormatByMode(mode: string): string {

src/demo/demo/date-pickers/day-time/day-time-demo/day-time-demo.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {Component, OnInit} from '@angular/core';
2-
import {DateComponent} from '../../common/date-component.component';
2+
import {DateComponent} from '../../../common/date-component.component';
33
import {FormControl} from '@angular/forms';
44
import {IDatePickerConfig} from '../../../../../lib';
5-
import {DEF_CONF} from '../../common/conts/consts';
5+
import {DEF_CONF} from '../../../common/conts/consts';
66

77
@Component({
88
selector: 'dp-day-time-demo',

src/demo/demo/date-pickers/day-time/day-time-directive-demo/day-time-directive-demo.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Component, OnInit} from '@angular/core';
2-
import {DateComponent} from '../../common/date-component.component';
2+
import {DateComponent} from '../../../common/date-component.component';
33
import {FormControl} from '@angular/forms';
4-
import {DEF_CONF} from '../../common/conts/consts';
4+
import {DEF_CONF} from '../../../common/conts/consts';
55
import {IDatePickerConfig} from '../../../../../lib';
66

77
@Component({

0 commit comments

Comments
 (0)