Skip to content

fix(cdk-experimental/listbox): fix issue with aria-selected #25373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/cdk-experimental/listbox/listbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ The available CSS classes are listed below, by directive.

In addition to CSS classes, these directives add aria attributes that can be targeted in CSS.

| Directive | Attribute Selector | Applied... |
|:-----------|----------------------------------|------------------------------------------|
| cdkOption | \[aria-disabled="true"] | If the option is disabled |
| cdkOption | \[aria-selected="true"] | If the option is selected |
| cdkListbox | \[aria-disabled="true"] | If the listbox is selected |
| cdkListbox | \[aria-multiselectable="true"] | If the listbox allows multiple selection |
| cdkListbox | \[aria-orientation="horizontal"] | If the listbox is oriented horizontally |
| cdkListbox | \[aria-orientation="vertical"] | If the listbox is oriented vertically |
| Directive | Attribute Selector | Applied... |
|:-----------|----------------------------------|-----------------------------------------|
| cdkOption | \[aria-disabled="true"] | If the option is disabled |
| cdkOption | \[aria-disabled="false"] | If the option is not disabled |
| cdkOption | \[aria-selected="true"] | If the option is selected |
| cdkOption | \[aria-selected="false"] | If the option is not selected |
| cdkListbox | \[aria-disabled="true"] | If the listbox is disabled |
| cdkListbox | \[aria-disabled="false"] | If the listbox is not disabled |
| cdkListbox | \[aria-multiselectable="true"] | If the listbox is multiple selection |
| cdkListbox | \[aria-multiselectable="false"] | If the listbox is single selection |
| cdkListbox | \[aria-orientation="horizontal"] | If the listbox is oriented horizontally |
| cdkListbox | \[aria-orientation="vertical"] | If the listbox is oriented vertically |

### Getting started

Expand Down
2 changes: 1 addition & 1 deletion src/cdk-experimental/listbox/listbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('CdkOption and CdkListbox', () => {
expect(listbox.value).toEqual([]);
for (let i = 0; i < options.length; i++) {
expect(options[i].isSelected()).toBeFalse();
expect(optionEls[i].hasAttribute('aria-selected')).toBeFalse();
expect(optionEls[i].getAttribute('aria-selected')).toBe('false');
}
expect(fixture.componentInstance.changedOption).toBeUndefined();
});
Expand Down
8 changes: 4 additions & 4 deletions src/cdk-experimental/listbox/listbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ class ListboxSelectionModel<T> extends SelectionModel<T> {
'role': 'option',
'class': 'cdk-option',
'[id]': 'id',
'[attr.aria-selected]': 'isSelected() || null',
'[attr.aria-selected]': 'isSelected()',
'[attr.tabindex]': '_getTabIndex()',
'[attr.aria-disabled]': 'disabled || null',
'[attr.aria-disabled]': 'disabled',
'[class.cdk-option-active]': 'isActive()',
'(click)': '_clicked.next($event)',
'(focus)': '_handleFocus()',
Expand Down Expand Up @@ -243,8 +243,8 @@ export class CdkOption<T = unknown> implements ListKeyManagerOption, Highlightab
'class': 'cdk-listbox',
'[id]': 'id',
'[attr.tabindex]': '_getTabIndex()',
'[attr.aria-disabled]': 'disabled || null',
'[attr.aria-multiselectable]': 'multiple || null',
'[attr.aria-disabled]': 'disabled',
'[attr.aria-multiselectable]': 'multiple',
'[attr.aria-activedescendant]': '_getAriaActiveDescendant()',
'[attr.aria-orientation]': 'orientation',
'(focus)': '_handleFocus()',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
padding: 5px 5px 5px 25px;
}

.example-option[aria-selected]::before {
.example-option[aria-selected='true']::before {
content: '';
display: block;
width: 20px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
padding: 5px 5px 5px 25px;
}

.example-option[aria-selected]::before {
.example-option[aria-selected='true']::before {
content: '';
display: block;
width: 20px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
padding: 5px 5px 5px 25px;
}

.example-option[aria-selected]::before {
.example-option[aria-selected='true']::before {
content: '';
display: block;
width: 20px;
Expand All @@ -31,10 +31,10 @@
left: 2px;
}

.example-option[aria-disabled] {
.example-option[aria-disabled='true'] {
opacity: 0.5;
}

.example-option:not([aria-disabled]):focus {
.example-option[aria-disabled='false']:focus {
background: rgba(0, 0, 0, 0.2);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
padding: 5px 5px 5px 25px;
}

.example-option[aria-selected]::before {
.example-option[aria-selected='true']::before {
content: '';
display: block;
width: 20px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
padding: 5px 5px 5px 25px;
}

.example-option[aria-selected]::before {
.example-option[aria-selected='true']::before {
content: '';
display: block;
width: 20px;
Expand All @@ -39,11 +39,11 @@
left: 2px;
}

.example-option[aria-disabled] {
.example-option[aria-disabled='true'] {
opacity: 0.5;
}

.example-option:not([aria-disabled]):focus {
.example-option[aria-disabled='false']:focus {
background: rgba(0, 0, 0, 0.2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
padding: 5px 5px 5px 25px;
}

.example-option[aria-selected]::before {
.example-option[aria-selected='true']::before {
content: '';
display: block;
width: 20px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
border-left-width: 1px;
}

.example-option[aria-selected]::before {
.example-option[aria-selected='true']::before {
content: '';
position: absolute;
border: 2px solid black;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
padding: 5px 5px 5px 25px;
}

.example-option[aria-selected]::before {
.example-option[aria-selected='true']::before {
content: '';
display: block;
width: 20px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
padding: 5px 5px 5px 25px;
}

.example-option[aria-selected]::before {
.example-option[aria-selected='true']::before {
content: '';
display: block;
width: 20px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
padding: 5px 5px 5px 25px;
}

.example-option[aria-selected]::before {
.example-option[aria-selected='true']::before {
content: '';
display: block;
width: 20px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
padding: 5px 5px 5px 25px;
}

.example-option[aria-selected]::before {
.example-option[aria-selected='true']::before {
content: '';
display: block;
width: 20px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
padding: 5px 5px 5px 25px;
}

.example-option[aria-selected]::before {
.example-option[aria-selected='true']::before {
content: '';
display: block;
width: 20px;
Expand Down