Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/primefaces/primeng
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmetcetin01140 committed Nov 20, 2023
2 parents 4465998 + 7696b96 commit 480b6e2
Show file tree
Hide file tree
Showing 27 changed files with 428 additions and 502 deletions.
33 changes: 28 additions & 5 deletions src/app/components/autocomplete/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export const AUTOCOMPLETE_VALUE_ACCESSOR: any = {
<p-overlay
#overlay
[(visible)]="overlayVisible"
[options]="virtualScrollOptions"
[options]="overlayOptions"
[target]="'@parent'"
[appendTo]="appendTo"
[showTransitionOptions]="showTransitionOptions"
Expand All @@ -197,7 +197,6 @@ export const AUTOCOMPLETE_VALUE_ACCESSOR: any = {
*ngIf="virtualScroll"
#scroller
[items]="visibleOptions()"
[tabindex]="-1"
[style]="{ height: scrollHeight }"
[itemSize]="virtualScrollItemSize || _itemSize"
[autoSize]="true"
Expand Down Expand Up @@ -1055,9 +1054,12 @@ export class AutoComplete implements AfterViewChecked, AfterContentInit, OnDestr
this.updateModel(query);
}

if (query.length === 0) {
this.hide();
if (query.length === 0 && !this.multiple) {
this.onClear.emit();

setTimeout(() => {
this.hide();
}, this.delay / 2);
} else {
if (query.length >= this.minLength) {
this.focusedOptionIndex.set(-1);
Expand Down Expand Up @@ -1240,6 +1242,7 @@ export class AutoComplete implements AfterViewChecked, AfterContentInit, OnDestr
this.changeFocusedOptionIndex(event, optionIndex);

event.preventDefault();
event.stopPropagation();
}

onArrowUpKey(event) {
Expand All @@ -1260,6 +1263,7 @@ export class AutoComplete implements AfterViewChecked, AfterContentInit, OnDestr
this.changeFocusedOptionIndex(event, optionIndex);

event.preventDefault();
event.stopPropagation();
}
}

Expand Down Expand Up @@ -1566,7 +1570,26 @@ export class AutoComplete implements AfterViewChecked, AfterContentInit, OnDestr
onOverlayAnimationStart(event: AnimationEvent) {
if (event.toState === 'visible') {
this.itemsWrapper = DomHandler.findSingle(this.overlayViewChild.overlayViewChild?.nativeElement, this.virtualScroll ? '.p-scroller' : '.p-autocomplete-panel');
this.virtualScroll && this.scroller?.setContentEl(this.itemsViewChild?.nativeElement);

if(this.virtualScroll) {
this.scroller?.setContentEl(this.itemsViewChild?.nativeElement);
this.scroller.viewInit();
}
if(this.visibleOptions() && this.visibleOptions().length) {
if(this.virtualScroll) {
const selectedIndex = this.modelValue() ? this.focusedOptionIndex() : -1;

if (selectedIndex !== -1) {
this.scroller?.scrollToIndex(selectedIndex);
}
} else {
let selectedListItem = DomHandler.findSingle(this.itemsWrapper, '.p-autocomplete-item.p-highlight');

if (selectedListItem) {
selectedListItem.scrollIntoView({ block: 'nearest', inline: 'center' });
}
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/components/chips/chips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const CHIPS_VALUE_ACCESSOR: any = {
host: {
class: 'p-element p-inputwrapper',
'[class.p-inputwrapper-filled]': 'filled',
'[class.p-inputwrapper-focus]': 'focus',
'[class.p-inputwrapper-focus]': 'focused',
'[class.p-chips-clearable]': 'showClear'
},
providers: [CHIPS_VALUE_ACCESSOR],
Expand Down
60 changes: 32 additions & 28 deletions src/app/components/dropdown/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class DropdownItem {
(blur)="onInputBlur($event)"
(keydown)="onKeyDown($event)"
>
<ng-container *ngIf="!selectedItemTemplate; else defaultPlaceholder">{{ label() === 'p-emptylabel' ? '&nbsp;' : label() || 'empty' }}</ng-container>
<ng-container *ngIf="!selectedItemTemplate; else defaultPlaceholder">{{ label() === 'p-emptylabel' ? '&nbsp;' : label() }}</ng-container>
<ng-container *ngTemplateOutlet="selectedItemTemplate; context: { $implicit: modelValue() }"></ng-container>
<ng-template #defaultPlaceholder>
<span *ngIf="label() === placeholder || (label() && !placeholder)">{{ label() === 'p-emptylabel' ? '&nbsp;' : placeholder }}</span>
Expand Down Expand Up @@ -902,9 +902,9 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV
});

label = computed(() => {
let selectedOptionIndex;
this.autoDisplayFirst ? (!this.modelValue() ? (selectedOptionIndex = -1) : (selectedOptionIndex = this.findFirstOptionIndex())) : (selectedOptionIndex = this.findSelectedOptionIndex());
return this.modelValue() ? this.getOptionLabel(this.modelValue()) : selectedOptionIndex !== -1 ? this.getOptionLabel(this.visibleOptions()[selectedOptionIndex]) : this.placeholder || 'p-emptylabel';
const selectedOptionIndex = this.findSelectedOptionIndex();

return selectedOptionIndex !== -1 ? this.getOptionLabel(this.visibleOptions()[selectedOptionIndex]) : this.placeholder || 'p-emptylabel';
});

constructor(public el: ElementRef, public renderer: Renderer2, public cd: ChangeDetectorRef, public zone: NgZone, public filterService: FilterService, public config: PrimeNGConfig) {
Expand Down Expand Up @@ -1028,15 +1028,16 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV
}
if (this.autoDisplayFirst && !this.modelValue()) {
const ind = this.findFirstOptionIndex();
this.onOptionSelect(null, this.visibleOptions()[ind], false);
this.onOptionSelect(null, this.visibleOptions()[ind], false, true);
}
}

onOptionSelect(event, option, isHide = true) {
onOptionSelect(event, option, isHide = true, preventChange = false) {
const value = this.getOptionValue(option);
this.updateModel(value, event);
this.focusedOptionIndex.set(this.findSelectedOptionIndex());
isHide && this.hide(true);
(preventChange === false) && this.onChange.emit({originalEvent: event, value: value});
}

onOptionMouseEnter(event, index) {
Expand All @@ -1048,16 +1049,26 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV
updateModel(value, event?) {
this.value = value;
this.onModelChange(value);
if (this.value !== this.modelValue()) {
this.onChange.emit({
originalEvent: event,
value: value
});
}
this.modelValue.set(value);
this.selectedOptionUpdated = true;
}

writeValue(value: any): void {
if (this.filter) {
this.resetFilter();
}
this.value = value;

this.allowModelChange() && this.onModelChange(value);
this.modelValue.set(this.value)
this.updateEditableLabel();
this.cd.markForCheck();
}

allowModelChange(){
return this.autoDisplayFirst && !this.placeholder && !this.modelValue() && !this.editable && this.options && this.options.length;
}

isSelected(option) {
return this.isValidOption(option) && ObjectUtils.equals(this.modelValue(), this.getOptionValue(option), this.equalityKey());
}
Expand All @@ -1079,7 +1090,7 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV
}

getOptionLabel(option: any) {
return this.optionLabel ? ObjectUtils.resolveFieldData(option, this.optionLabel) : option && option.label !== undefined ? option.label : option;
return this.optionLabel ? ObjectUtils.resolveFieldData(option, this.optionLabel) : option && option?.label !== undefined ? option.label : option;
}

getOptionValue(option: any) {
Expand Down Expand Up @@ -1113,16 +1124,6 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV
return this.visibleOptions().filter((option) => !this.isOptionGroup(option)).length;
}

writeValue(value: any): void {
if (this.filter) {
this.resetFilter();
}
this.value = value;
this.updateModel(this.value);
this.updateEditableLabel();
this.cd.markForCheck();
}

/**
* Callback to invoke on filter reset.
* @group Method
Expand Down Expand Up @@ -1176,6 +1177,7 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV

this.onModelChange(value);
this.updateModel(value, event);
this.onChange.emit({originalEvent: event, value: value})
}
/**
* Displays the panel.
Expand All @@ -1201,13 +1203,13 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV
if (this.virtualScroll) {
const selectedIndex = this.modelValue() ? this.focusedOptionIndex() : -1;
if (selectedIndex !== -1) {
this.scroller?.scrollToIndex(0);
this.scroller?.scrollToIndex(selectedIndex);
}
} else {
let selectedListItem = DomHandler.findSingle(this.itemsWrapper, '.p-dropdown-item.p-highlight');

if (selectedListItem) {
selectedListItem.scrollIntoView({ block: 'nearest', inline: 'center' });
selectedListItem.scrollIntoView({ block: 'nearest', inline: 'nearest' });
}
}
}
Expand Down Expand Up @@ -1260,7 +1262,7 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV

onInputBlur(event: Event) {
this.focused = false;
this.onBlur.emit(event);
(this.overlayVisible === false) && this.onBlur.emit(event);

if (!this.preventModelTouched) {
this.onModelTouched();
Expand Down Expand Up @@ -1418,6 +1420,7 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV

scrollInView(index = -1) {
const id = index !== -1 ? `${this.id}_${index}` : this.focusedOptionId;

if (this.itemsViewChild && this.itemsViewChild.nativeElement) {
const element = DomHandler.findSingle(this.itemsViewChild.nativeElement, `li[id="${id}"]`);
if (element) {
Expand Down Expand Up @@ -1602,12 +1605,12 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV
}

onFirstHiddenFocus(event) {
const focusableEl = event.relatedTarget === this.focusInputViewChild.nativeElement ? DomHandler.getFirstFocusableElement(this.overlayViewChild.el.nativeElement, ':not(.p-hidden-focusable)') : this.focusInputViewChild.nativeElement;
const focusableEl = event.relatedTarget === this.focusInputViewChild?.nativeElement ? DomHandler.getFirstFocusableElement(this.overlayViewChild.el.nativeElement, ':not(.p-hidden-focusable)') : this.focusInputViewChild.nativeElement;
DomHandler.focus(focusableEl);
}

hasFocusableElements() {
return DomHandler.getFocusableElements(this.overlayViewChild.overlayViewChild.nativeElement, ':not(.p-hidden-focusable)').length > 0;
return DomHandler.getFocusableElements(this.overlayViewChild?.overlayViewChild?.nativeElement, ':not(.p-hidden-focusable)').length > 0;
}

onBackspaceKey(event: KeyboardEvent, pressedInInputText = false) {
Expand Down Expand Up @@ -1693,6 +1696,7 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV
clear(event: Event) {
this.updateModel(null, event);
this.updateEditableLabel();
this.onChange.emit({originalEvent: event, value: this.value})
this.onClear.emit(event);
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/app/components/fileupload/fileupload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,15 +743,22 @@ export class FileUpload implements AfterViewInit, AfterContentInit, OnInit, OnDe
}

isFileLimitExceeded() {
if (this.fileLimit && this.fileLimit <= this.files.length + this.uploadedFileCount && this.focus) {
const isAutoMode = this.auto;
const totalFileCount = isAutoMode ? this.files.length : this.files.length + this.uploadedFileCount;

if (this.fileLimit && this.fileLimit <= totalFileCount && this.focus) {
this.focus = false;
}

return this.fileLimit && this.fileLimit < this.files.length + this.uploadedFileCount;
return this.fileLimit && this.fileLimit < totalFileCount;
}

isChooseDisabled() {
return this.fileLimit && this.fileLimit <= this.files.length + this.uploadedFileCount;
if (this.auto) {
return this.fileLimit && this.fileLimit <= this.files.length;
} else {
return this.fileLimit && this.fileLimit <= this.files.length + this.uploadedFileCount;
}
}

checkFileLimit() {
Expand Down
15 changes: 15 additions & 0 deletions src/app/components/listbox/listbox.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ export interface ListboxChangeEvent {
*/
value: any;
}
/**
* Custom change event.
* @see {@link Listbox.onSelectAllChange}
* @group Events
*/
export interface ListboxSelectAllChangeEvent {
/**
* Browser event.
*/
originalEvent: Event;
/**
* Boolean value indicates whether all data is selected.
*/
checked: boolean;
}
/**
* Custom filter event.
* @see {@link Listbox.onFilter}
Expand Down
Loading

1 comment on commit 480b6e2

@vercel
Copy link

@vercel vercel bot commented on 480b6e2 Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.