Skip to content

Commit

Permalink
fix: Add proper messages for pickers (#3216)
Browse files Browse the repository at this point in the history
* fix: Add proper messages for pickers

* remove leftovers

* remove leftovers

* remove example changes

* change form message property name
  • Loading branch information
JKMarkowski committed Sep 10, 2020
1 parent 6281d1a commit 50b23b7
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 4 deletions.
2 changes: 2 additions & 0 deletions libs/core/src/lib/date-picker/date-picker.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<fd-popover
[(isOpen)]="isOpen"
(isOpenChange)="isOpenChange.emit($event)"
[triggers]="[]"
[placement]="placement"
[closeOnEscapeKey]="true"
Expand Down Expand Up @@ -37,6 +38,7 @@
</fd-input-group>
</fd-popover-control>
<fd-popover-body [style.display]="'block'" [attr.aria-expanded]="isOpen" [attr.aria-hidden]="!isOpen">
<ng-content></ng-content>
<fd-calendar
(closeCalendar)="closeFromCalendar()"
[activeView]="activeView"
Expand Down
14 changes: 11 additions & 3 deletions libs/core/src/lib/date-picker/date-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ export class DatePickerComponent implements ControlValueAccessor, Validator {
/** @hidden Whether the date input is invalid */
isInvalidDateInput = false;

/** @hidden Whether the date picker is open */
isOpen = false;

/** @hidden */
@ViewChild(CalendarComponent)
calendarComponent: CalendarComponent;
Expand Down Expand Up @@ -204,6 +201,14 @@ export class DatePickerComponent implements ControlValueAccessor, Validator {
@Input()
showWeekNumbers = true;

/** Whether the date picker is open. Can be used through two-way binding. */
@Input()
isOpen = false;

/** Event emitted when the state of the isOpen property changes. */
@Output()
isOpenChange = new EventEmitter<boolean>();

/** Fired when a new date is selected. */
@Output()
public readonly selectedDateChange: EventEmitter<FdDate> = new EventEmitter<FdDate>();
Expand Down Expand Up @@ -268,19 +273,22 @@ export class DatePickerComponent implements ControlValueAccessor, Validator {
if (!this.disabled) {
this.onTouched();
this.isOpen = true;
this.isOpenChange.emit(this.isOpen);
}
}

/** Toggles the calendar open or closed */
public toggleCalendar(): void {
this.onTouched();
this.isOpen = !this.isOpen;
this.isOpenChange.emit(this.isOpen);
}

/** Closes the calendar if it is open */
public closeCalendar(): void {
if (this.isOpen) {
this.isOpen = false;
this.isOpenChange.emit(this.isOpen);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
</fd-input-group>
</fd-popover-control>
<fd-popover-body [attr.aria-expanded]="isOpen" [attr.aria-hidden]="!isOpen" [style.display]="'block'">
<ng-content></ng-content>
<div class="fd-datetime__container">
<fd-calendar
calType="single"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ export class DatetimePickerComponent implements OnInit, OnDestroy, ControlValueA
@Input()
showFooter = true;

/** Event emitted when the state of the isOpen property changes. */
@Output()
isOpenChange = new EventEmitter<boolean>();

/** Event thrown every time calendar active view is changed */
@Output()
public readonly activeViewChange: EventEmitter<FdCalendarView> = new EventEmitter<FdCalendarView>();
Expand Down Expand Up @@ -363,6 +367,7 @@ export class DatetimePickerComponent implements OnInit, OnDestroy, ControlValueA
if (!this.isOpen && !this.disabled) {
this.onTouched();
this.isOpen = true;
this.isOpenChange.emit(this.isOpen);
this._activateTimeComponent();
}
}
Expand All @@ -373,6 +378,7 @@ export class DatetimePickerComponent implements OnInit, OnDestroy, ControlValueA
this.handleInputChange(this.inputFieldDate);
this.onClose.emit();
this.isOpen = false;
this.isOpenChange.emit(this.isOpen);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[ngClass]="[
type ? ' fd-form-message--' + type : '',
compact ? ' fd-form-message--' + compact : '',
static ? ' fd-form-message--static' : ''
static ? ' fd-form-message--static' : '',
embedded? ' fd-form-message--embedded' : ''
]"
>
<ng-content></ng-content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
.fd-form-message {
display: block;
}

.fd-form-message--embedded {
box-shadow: none;
max-width: 100%;
}
7 changes: 7 additions & 0 deletions libs/core/src/lib/form/form-message/form-message.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ export class FormMessageComponent {
/** Whether message should be in static mode, without popover. It's mostly used for forms component, that contain dropdown */
@Input()
static = false;

/**
* Whether message is used inside popovers or dialogs.
* When it is enabled box shadow is removed and message is expanded to whole container width
*/
@Input()
embedded = false;
}
1 change: 1 addition & 0 deletions libs/core/src/lib/time-picker/time-picker.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<fd-popover [(isOpen)]="isOpen"
(isOpenChange)="isOpenChange.emit($event)"
[triggers]="[]"
[disabled]="disabled"
[placement]="placement"
Expand Down
7 changes: 7 additions & 0 deletions libs/core/src/lib/time-picker/time-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
EventEmitter,
forwardRef,
HostBinding,
Input,
OnDestroy,
Output,
ViewChild,
ViewEncapsulation
} from '@angular/core';
Expand Down Expand Up @@ -131,6 +133,10 @@ export class TimePickerComponent implements ControlValueAccessor, OnDestroy, Aft
@Input()
keepTwoDigitsTime = false;

/** Event emitted when the state of the isOpen property changes. */
@Output()
isOpenChange = new EventEmitter<boolean>();

/** @hidden */
@HostBinding('class.fd-time-picker')
timePickerClass = true;
Expand Down Expand Up @@ -212,6 +218,7 @@ export class TimePickerComponent implements ControlValueAccessor, OnDestroy, Aft
*/
handleIsOpenChange(isOpen: boolean): void {
this.isOpen = isOpen;
this.isOpenChange.emit(this.isOpen);
if (isOpen) {
this.popover.directiveRef.loaded
.pipe(
Expand Down

0 comments on commit 50b23b7

Please sign in to comment.