Angular Aria Combobox and Listbox as hostDirectives mouse click functionality
维护者通常 1 天内回复
@ok7sai 已经在做这个了。
开始于 2026年4月1日。
评估
这个 Issue 还没有评估数据。
描述
Which @angular/* package(s) are the source of the bug?
Don't known / other
Is this a regression?
No
Description
When using hostDirectives to implement a Combobox, mouse click will only open the combobox and not close it. Also the Listbox within will not register mouse clicks on Option components. Below is nearly the same example from the Docs, but using hostDirectives.
TS
import {
Combobox,
ComboboxInput,
ComboboxPopup,
ComboboxPopupContainer,
} from "@angular/aria/combobox";
import { Listbox, Option } from "@angular/aria/listbox";
import {
afterRenderEffect,
ChangeDetectionStrategy,
Component,
computed,
viewChild,
viewChildren,
} from "@angular/core";
import { OverlayModule } from "@angular/cdk/overlay";
@Component({
selector: "mww-select",
templateUrl: "./mww-select.html",
styleUrl: "./mww-select.css",
host: { ngCombobox: "", readonly: "" },
hostDirectives: [{ directive: Combobox, inputs: ["readonly"] }],
imports: [
ComboboxInput,
ComboboxPopup,
ComboboxPopupContainer,
Listbox,
Option,
OverlayModule,
],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MwwSelect {
/** The combobox listbox popup. */
listbox = viewChild<Listbox<string>>(Listbox);
/** The options available in the listbox. */
options = viewChildren<Option<string>>(Option);
/** A reference to the ng aria combobox. */
combobox = viewChild<Combobox<string>>(Combobox);
/** The string that is displayed in the combobox. */
displayValue = computed(() => {
const values = this.listbox()?.values() || [];
if (values.length === 0) {
return "Select a label";
}
if (values.length === 1) {
return values[0];
}
return `${values[0]} + ${values.length - 1} more`;
});
/** The labels that are available for selection. */
labels = [
"Important",
"Starred",
"Work",
"Personal",
"To Do",
"Later",
"Read",
"Travel",
];
constructor() {
// Scrolls to the active item when the active option changes.
// The slight delay here is to ensure animations are done before scrolling.
afterRenderEffect(() => {
const option = this.options().find((opt) => opt.active());
setTimeout(
() => option?.element.scrollIntoView({ block: "nearest" }),
50,
);
});
// Resets the listbox scroll position when the combobox is closed.
afterRenderEffect(() => {
if (!this.combobox()?.expanded()) {
setTimeout(() => this.listbox()?.element.scrollTo(0, 0), 150);
}
});
}
}
Component HTML
<div #origin class="select">
<span class="combobox-label">
<span class="selected-label-text">{{ displayValue() }}</span>
</span>
<input aria-label="Label dropdown" placeholder="Select a label" ngComboboxInput />
<span class="example-arrow material-symbols-outlined" translate="no">arrow_drop_down</span>
</div>
<ng-template ngComboboxPopupContainer>
<ng-template [cdkConnectedOverlay]="{origin, usePopover: 'inline', matchWidth: true}"
[cdkConnectedOverlayOpen]="true">
<div class="example-popup-container">
<div ngListbox multi>
@for (label of labels; track label) {
<div ngOption [value]="label" [label]="label">
<span class="example-option-text">{{label}}</span>
<span class="example-option-check material-symbols-outlined" translate="no">check</span>
</div>
}
</div>
</div>
</ng-template>
</ng-template>
Usage HTML
<mww-select></mww-select>
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run ng version)
Angular CLI : 21.0.0
Angular : 21.0.0
Node.js : 22.18.0
Package Manager : npm 10.8.1
Operating System : win32 x64
┌───────────────────────────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├───────────────────────────────────┼───────────────────┼───────────────────┤
│ @angular-devkit/build-angular │ 21.0.0 │ ^21.0.0 │
│ @angular/animations │ 21.0.0 │ ^21.0.0 │
│ @angular/aria │ 21.0.0 │ ^21.0.0 │
│ @angular/cdk │ 21.0.0 │ ^21.0.0 │
│ @angular/cli │ 21.0.0 │ ^21.0.0 │
│ @angular/common │ 21.0.0 │ ^21.0.0 │
│ @angular/compiler │ 21.0.0 │ ^21.0.0 │
│ @angular/compiler-cli │ 21.0.0 │ ^21.0.0 │
│ @angular/core │ 21.0.0 │ ^21.0.0 │
│ @angular/forms │ 21.0.0 │ ^21.0.0 │
│ @angular/material │ 21.0.0 │ ^21.0.0 │
│ @angular/platform-browser │ 21.0.0 │ ^21.0.0 │
│ @angular/platform-browser-dynamic │ 21.0.0 │ ^21.0.0 │
│ @angular/router │ 21.0.0 │ ^21.0.0 │
│ rxjs │ 7.8.2 │ ^7.5.5 │
│ typescript │ 5.9.3 │ ^5.9.3 │
│ zone.js │ 0.15.1 │ ^0.15.1 │
└───────────────────────────────────┴───────────────────┴───────────────────┘
Anything else?
No response
- 主要语言
- TypeScript
- 星标
- 25k
- 派生
- 6.8k
- 平均合并
- 1 天 5 小时
- 30 天内合并 PR
- 67
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
angular/components 的其他 Issue
-
bug(aria/combobox): keys pressed back to back are lost; only the last one reaches the popup可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭area: aria/combobox gemini-triaged
难度 2/5 1-3 小时 新手友好度 78/100
angular/components#33973 ·
维护者通常 1 天内回复
-
bug(aria/combobox): ComboboxPopup throws NG0950 when destroyed before its first change detection可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭area: aria/combobox gemini-triaged
难度 2/5 1-3 小时 新手友好度 78/100
angular/components#33972 ·
维护者通常 1 天内回复
-
bug(material/sort): hover hint arrow on an unsorted header shows the active sort direction, not the resulting direction after click.可能已有人在做 @lekhmanrus 于 12 天前认领。 未关闭area: material/sort P3
难度 2/5 1-3 小时 新手友好度 70/100
angular/components#33933 ·
维护者通常 1 天内回复
-
bug(mat-date-picker): month shown twice in date picker可能已有人在做 @PreethiPantangi 于 29 天前认领。 未关闭area: material/datepicker P4
难度 2/5 1-3 小时 新手友好度 72/100
angular/components#33763 · 2 条评论 · 3 个 reaction ·
维护者通常 1 天内回复
-
Bug in table.scss footer cell height: unset instead of footer row height unset可能已有人在做 @minwookshin 于 16 天前认领。 未关闭area: material/table P4
难度 1/5 1 小时以内 新手友好度 88/100
angular/components#33709 · 1 条评论 ·
维护者通常 1 天内回复
查看 angular/components 的全部 Issue
相似的 Issue
-
area: repo priority: P2 type: bug
难度 2/5 1-3 小时 新手友好度 76/100
appandflow/stim#4107 · 1 条评论 ·
维护者通常 1 天内回复
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
难度 1/5 1-3 小时 新手友好度 60/100
lingdojo/kana-dojo#32859 · 1 条评论 · 5 个 reaction ·
维护者通常 1 天内回复
-
code-quality refactoring
难度 2/5 1-3 小时 新手友好度 78/100
github/gh-aw-firewall#10364 ·
维护者通常 1 天内回复
-
Merge the duplicate kaffir_corn record into sorghum可能已有人在做 @Crypto-Shroom 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 65/100
Crypto-Shroom/Bird-Feed-Calculator#322 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
drizzle-team/drizzle-orm#6552 ·
维护者通常 2 天内回复