Skip to content

Commit 7fe25b5

Browse files
felipepetucoalinelariguet
authored andcommitted
fix(select): trata placeholder quando é Safari
1 parent 196ba3e commit 7fe25b5

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

projects/ui/src/lib/components/po-field/po-select/po-select.component.html

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,23 @@
1717
[required]="required"
1818
(change)="onSelectChange($event.target.value)"
1919
>
20-
<option
21-
*ngIf="!selectedValue?.toString() || !!placeholder"
22-
[disabled]="!!placeholder"
23-
[hidden]="!selectedValue?.toString() && !placeholder"
24-
[selected]="!selectedValue?.toString()"
25-
[value]="placeholder ?? ''"
26-
>
27-
{{ placeholder }}
28-
</option>
29-
<!-- necessário manter essa option para uso do select com ReactiveForms -->
30-
<option [hidden]="true">
31-
{{ displayValue }}
32-
</option>
20+
<ng-container *ngIf="!isSafari">
21+
<option
22+
*ngIf="!selectedValue?.toString() || !!placeholder"
23+
[disabled]="!!placeholder"
24+
[hidden]="!selectedValue?.toString() && !placeholder"
25+
[selected]="!selectedValue?.toString()"
26+
[value]="placeholder ?? ''"
27+
>
28+
{{ placeholder }}
29+
</option>
30+
<option [hidden]="true">{{ displayValue }}</option>
31+
</ng-container>
32+
33+
<ng-container *ngIf="isSafari">
34+
<option>{{ displayValue || placeholder }}</option>
35+
</ng-container>
36+
3337
<ng-container *ngIf="optionWithoutGroup.length > 0">
3438
<option *ngFor="let item of optionWithoutGroup" [disabled]="readonly" [value]="item?.[this.fieldValue]">
3539
{{ item?.[this.fieldLabel] }}

projects/ui/src/lib/components/po-field/po-select/po-select.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { AbstractControl, NG_VALIDATORS, NG_VALUE_ACCESSOR } from '@angular/form
1616

1717
import {
1818
convertToBoolean,
19+
isSafari,
1920
removeDuplicatedOptions,
2021
removeUndefinedAndNullOptions,
2122
uuid,
@@ -128,6 +129,7 @@ export class PoSelectComponent extends PoFieldValidateModel<any> implements OnCh
128129
optionsDefault = [];
129130
listGroupOptions = [];
130131
optionWithoutGroup = [];
132+
isSafari: boolean = isSafari();
131133

132134
protected onModelTouched: any;
133135

projects/ui/src/lib/utils/util.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ export function isFirefox() {
233233
return userAgent.toLowerCase().indexOf('firefox') > -1;
234234
}
235235

236+
// Verifica se o navegador em que está sendo usado é Safari
237+
export function isSafari() {
238+
const userAgent = window.navigator.userAgent;
239+
240+
return /^(?!.*chrome).*safari.*$/.test(userAgent.toLocaleLowerCase());
241+
}
242+
236243
// Verifica qual o dispositivo que está sendo usado
237244
export function isMobile() {
238245
const userAgent = window.navigator.userAgent;

0 commit comments

Comments
 (0)