Skip to content

Commit

Permalink
Dropdown | Accessibility enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
cetincakiroglu committed Oct 4, 2023
1 parent 3281dee commit f52340b
Show file tree
Hide file tree
Showing 52 changed files with 6,122 additions and 1,102 deletions.
26 changes: 18 additions & 8 deletions src/app/components/dom/domhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,23 +606,33 @@ export class DomHandler {
element && document.activeElement !== element && element.focus(options);
}

public static getFocusableElements(element: HTMLElement) {
let focusableElements = DomHandler.find(
public static getFocusableElements(element, selector = '') {
let focusableElements = this.find(
element,
`button:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]),
[href]:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]),
input:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]), select:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]),
textarea:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]), [tabIndex]:not([tabIndex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]),
[contenteditable]:not([tabIndex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]):not(.p-disabled)`
`button:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${selector},
[href][clientHeight][clientWidth]:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${selector},
input:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${selector},
select:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${selector},
textarea:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${selector},
[tabIndex]:not([tabIndex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${selector},
[contenteditable]:not([tabIndex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${selector}`
);

let visibleFocusableElements = [];

for (let focusableElement of focusableElements) {
if (!!(focusableElement.offsetWidth || focusableElement.offsetHeight || focusableElement.getClientRects().length)) visibleFocusableElements.push(focusableElement);
if (getComputedStyle(focusableElement).display != 'none' && getComputedStyle(focusableElement).visibility != 'hidden') visibleFocusableElements.push(focusableElement);
}

return visibleFocusableElements;
}

public static getFirstFocusableElement(element, selector) {
const focusableElements = this.getFocusableElements(element, selector);

return focusableElements.length > 0 ? focusableElements[0] : null;
}

public static getNextFocusableElement(element: HTMLElement, reverse = false) {
const focusableElements = DomHandler.getFocusableElements(element);
let index = 0;
Expand Down
24 changes: 19 additions & 5 deletions src/app/components/dropdown/dropdown.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
.p-dropdown-clear-icon {
position: absolute;
top: 50%;
margin-top: -.5rem;
margin-top: -0.5rem;
}

.p-dropdown-trigger {
Expand All @@ -30,13 +30,23 @@

.p-dropdown-label-empty {
overflow: hidden;
visibility: hidden;
opacity: 0;
}

input.p-dropdown-label {
input.p-dropdown-label {
cursor: default;
}

.p-dropdown .p-dropdown-panel {
min-width: 100%;
}

.p-dropdown-panel {
position: absolute;
top: 0;
left: 0;
}

.p-dropdown-items-wrapper {
overflow: auto;
}
Expand All @@ -49,6 +59,10 @@ input.p-dropdown-label {
overflow: hidden;
}

.p-dropdown-item-group {
cursor: auto;
}

.p-dropdown-items {
margin: 0;
padding: 0;
Expand All @@ -66,7 +80,7 @@ input.p-dropdown-label {
.p-dropdown-filter-icon {
position: absolute;
top: 50%;
margin-top: -.5rem;
margin-top: -0.5rem;
}

.p-fluid .p-dropdown {
Expand All @@ -75,4 +89,4 @@ input.p-dropdown-label {

.p-fluid .p-dropdown .p-dropdown-label {
width: 1%;
}
}
1,165 changes: 686 additions & 479 deletions src/app/components/dropdown/dropdown.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/app/showcase/doc/dropdown/groupdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Code } from '../../domain/code';
<p>Options can be grouped when a nested data structures is provided.</p>
</app-docsectiontext>
<div class="card flex justify-content-center">
<p-dropdown [options]="groupedCities" [(ngModel)]="selectedCity" placeholder="Select a City" [group]="true">
<p-dropdown [options]="groupedCities" optionLabel="label" optionGroupLabel="label" optionGroupChildren="items" [(ngModel)]="selectedCity" placeholder="Select a City" [group]="true">
<ng-template let-group pTemplate="group">
<div class="flex align-items-center">
<img src="https://primefaces.org/cdn/primeng/images/demo/flag/flag_placeholder.png" [class]="'mr-2 flag flag-' + group.value" style="width: 20px" />
Expand Down
123 changes: 106 additions & 17 deletions src/assets/components/themes/arya-blue/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -1097,24 +1097,113 @@ p-inputmask.p-inputmask-clearable .p-inputmask-clear-icon {
right: 0.5rem;
}

p-inputnumber.ng-dirty.ng-invalid > .p-inputnumber > .p-inputtext {
border-color: #ef9a9a;
}

p-inputnumber.p-inputnumber-clearable .p-inputnumber-input {
padding-right: 2rem;
}
p-inputnumber.p-inputnumber-clearable .p-inputnumber-clear-icon {
color: rgba(255, 255, 255, 0.6);
right: 0.5rem;
}
.p-dropdown {
background: #121212;
border: 1px solid #383838;
transition: background-color 0.2s, color 0.2s, border-color 0.2s, box-shadow 0.2s;
border-radius: 3px;
}
.p-dropdown:not(.p-disabled):hover {
border-color: #64B5F6;
}
.p-dropdown:not(.p-disabled).p-focus {
outline: 0 none;
outline-offset: 0;
box-shadow: 0 0 0 1px #93cbf9;
border-color: #64B5F6;
}
.p-dropdown.p-dropdown-clearable .p-dropdown-label {
padding-right: 1.5rem;
}
.p-dropdown .p-dropdown-label {
background: transparent;
border: 0 none;
}
.p-dropdown .p-dropdown-label.p-placeholder {
color: rgba(255, 255, 255, 0.6);
}
.p-dropdown .p-dropdown-label:focus, .p-dropdown .p-dropdown-label:enabled:focus {
outline: 0 none;
box-shadow: none;
}
.p-dropdown .p-dropdown-trigger {
background: transparent;
color: rgba(255, 255, 255, 0.6);
width: 2.357rem;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
}
.p-dropdown .p-dropdown-clear-icon {
color: rgba(255, 255, 255, 0.6);
right: 2.357rem;
}
.p-dropdown.p-invalid.p-component {
border-color: #ef9a9a;
}

p-inputnumber.p-inputnumber-clearable .p-inputnumber-buttons-stacked .p-inputnumber-clear-icon {
right: 2.857rem;
}
p-inputnumber.p-inputnumber-clearable .p-inputnumber-buttons-horizontal .p-inputnumber-clear-icon {
right: 2.857rem;
}
.p-dropdown-panel {
background: #1e1e1e;
color: rgba(255, 255, 255, 0.87);
border: 1px solid #383838;
border-radius: 3px;
box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.2), 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12);
}
.p-dropdown-panel .p-dropdown-header {
padding: 0.5rem 1rem;
border-bottom: 0 none;
color: rgba(255, 255, 255, 0.87);
background: #1e1e1e;
margin: 0;
border-top-right-radius: 3px;
border-top-left-radius: 3px;
}
.p-dropdown-panel .p-dropdown-header .p-dropdown-filter {
padding-right: 1.5rem;
margin-right: -1.5rem;
}
.p-dropdown-panel .p-dropdown-header .p-dropdown-filter-icon {
right: 0.5rem;
color: rgba(255, 255, 255, 0.6);
}
.p-dropdown-panel .p-dropdown-items {
padding: 0.5rem 0;
}
.p-dropdown-panel .p-dropdown-items .p-dropdown-item {
margin: 0;
padding: 0.5rem 1rem;
border: 0 none;
color: rgba(255, 255, 255, 0.87);
background: transparent;
transition: box-shadow 0.2s;
border-radius: 0;
}
.p-dropdown-panel .p-dropdown-items .p-dropdown-item.p-highlight {
color: rgba(255, 255, 255, 0.87);
background: rgba(100, 181, 246, 0.16);
}
.p-dropdown-panel .p-dropdown-items .p-dropdown-item.p-highlight.p-focus {
background: rgba(100, 181, 246, 0.24);
}
.p-dropdown-panel .p-dropdown-items .p-dropdown-item:not(.p-highlight):not(.p-disabled).p-focus {
color: rgba(255, 255, 255, 0.87);
background: rgba(255, 255, 255, 0.09);
}
.p-dropdown-panel .p-dropdown-items .p-dropdown-item:not(.p-highlight):not(.p-disabled):hover {
color: rgba(255, 255, 255, 0.87);
background: rgba(255, 255, 255, 0.03);
}
.p-dropdown-panel .p-dropdown-items .p-dropdown-item-group {
margin: 0;
padding: 0.75rem 1rem;
color: rgba(255, 255, 255, 0.87);
background: #1e1e1e;
font-weight: 600;
}
.p-dropdown-panel .p-dropdown-items .p-dropdown-empty-message {
padding: 0.5rem 1rem;
color: rgba(255, 255, 255, 0.87);
background: transparent;
}

.p-inputswitch {
width: 3rem;
Expand Down
123 changes: 106 additions & 17 deletions src/assets/components/themes/arya-green/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -1097,24 +1097,113 @@ p-inputmask.p-inputmask-clearable .p-inputmask-clear-icon {
right: 0.5rem;
}

p-inputnumber.ng-dirty.ng-invalid > .p-inputnumber > .p-inputtext {
border-color: #ef9a9a;
}

p-inputnumber.p-inputnumber-clearable .p-inputnumber-input {
padding-right: 2rem;
}
p-inputnumber.p-inputnumber-clearable .p-inputnumber-clear-icon {
color: rgba(255, 255, 255, 0.6);
right: 0.5rem;
}
.p-dropdown {
background: #121212;
border: 1px solid #383838;
transition: background-color 0.2s, color 0.2s, border-color 0.2s, box-shadow 0.2s;
border-radius: 3px;
}
.p-dropdown:not(.p-disabled):hover {
border-color: #81C784;
}
.p-dropdown:not(.p-disabled).p-focus {
outline: 0 none;
outline-offset: 0;
box-shadow: 0 0 0 1px #a7d8a9;
border-color: #81C784;
}
.p-dropdown.p-dropdown-clearable .p-dropdown-label {
padding-right: 1.5rem;
}
.p-dropdown .p-dropdown-label {
background: transparent;
border: 0 none;
}
.p-dropdown .p-dropdown-label.p-placeholder {
color: rgba(255, 255, 255, 0.6);
}
.p-dropdown .p-dropdown-label:focus, .p-dropdown .p-dropdown-label:enabled:focus {
outline: 0 none;
box-shadow: none;
}
.p-dropdown .p-dropdown-trigger {
background: transparent;
color: rgba(255, 255, 255, 0.6);
width: 2.357rem;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
}
.p-dropdown .p-dropdown-clear-icon {
color: rgba(255, 255, 255, 0.6);
right: 2.357rem;
}
.p-dropdown.p-invalid.p-component {
border-color: #ef9a9a;
}

p-inputnumber.p-inputnumber-clearable .p-inputnumber-buttons-stacked .p-inputnumber-clear-icon {
right: 2.857rem;
}
p-inputnumber.p-inputnumber-clearable .p-inputnumber-buttons-horizontal .p-inputnumber-clear-icon {
right: 2.857rem;
}
.p-dropdown-panel {
background: #1e1e1e;
color: rgba(255, 255, 255, 0.87);
border: 1px solid #383838;
border-radius: 3px;
box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.2), 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12);
}
.p-dropdown-panel .p-dropdown-header {
padding: 0.5rem 1rem;
border-bottom: 0 none;
color: rgba(255, 255, 255, 0.87);
background: #1e1e1e;
margin: 0;
border-top-right-radius: 3px;
border-top-left-radius: 3px;
}
.p-dropdown-panel .p-dropdown-header .p-dropdown-filter {
padding-right: 1.5rem;
margin-right: -1.5rem;
}
.p-dropdown-panel .p-dropdown-header .p-dropdown-filter-icon {
right: 0.5rem;
color: rgba(255, 255, 255, 0.6);
}
.p-dropdown-panel .p-dropdown-items {
padding: 0.5rem 0;
}
.p-dropdown-panel .p-dropdown-items .p-dropdown-item {
margin: 0;
padding: 0.5rem 1rem;
border: 0 none;
color: rgba(255, 255, 255, 0.87);
background: transparent;
transition: box-shadow 0.2s;
border-radius: 0;
}
.p-dropdown-panel .p-dropdown-items .p-dropdown-item.p-highlight {
color: rgba(255, 255, 255, 0.87);
background: rgba(129, 199, 132, 0.16);
}
.p-dropdown-panel .p-dropdown-items .p-dropdown-item.p-highlight.p-focus {
background: rgba(129, 199, 132, 0.24);
}
.p-dropdown-panel .p-dropdown-items .p-dropdown-item:not(.p-highlight):not(.p-disabled).p-focus {
color: rgba(255, 255, 255, 0.87);
background: rgba(255, 255, 255, 0.09);
}
.p-dropdown-panel .p-dropdown-items .p-dropdown-item:not(.p-highlight):not(.p-disabled):hover {
color: rgba(255, 255, 255, 0.87);
background: rgba(255, 255, 255, 0.03);
}
.p-dropdown-panel .p-dropdown-items .p-dropdown-item-group {
margin: 0;
padding: 0.75rem 1rem;
color: rgba(255, 255, 255, 0.87);
background: #1e1e1e;
font-weight: 600;
}
.p-dropdown-panel .p-dropdown-items .p-dropdown-empty-message {
padding: 0.5rem 1rem;
color: rgba(255, 255, 255, 0.87);
background: transparent;
}

.p-inputswitch {
width: 3rem;
Expand Down
Loading

0 comments on commit f52340b

Please sign in to comment.