Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 925x 948x 948x 948x 948x 1x 1x 1112x 1112x 1x 1x 948x 948x 948x 1x 1x 1x 1x 55905x 55905x 1x 1x 55905x 55905x 1x 1x 954x 954x 1x 1x 1187x 1187x 133x 1187x 1187x 1x 1x 195x 195x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 925x 925x 925x 925x 925x 925x 925x 24x 24x 925x 24x 925x 925x 925x 1x 1x 1x 24x 24x 24x 1x 1x 1x 2x 2x 1x 1x 1x 24x 24x 1x 1x 1x 204x 204x 204x 204x 1x 1x 954x 954x 954x 1x 1x 211x 211x 211x 211x 211x 1x 1x 948x 948x 948x 948x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 948x 1x 1x 82x 82x 82x 82x 82x 82x 82x 82x 82x 82x 82x 82x 82x 82x 82x 82x 82x 1x | import { ContentChild, ContentChildren, Directive, ElementRef, HostBinding, HostListener, Input, NgZone, OnDestroy, QueryList, } from '@angular/core'; import { IndexedItem, handleActive, observeSize, } from '../utils/internal-utils'; import { Callback, Key } from '../utils/util.types'; import { BadgeComponent } from '../badge/badge.component'; import { VirtualListboxService } from './virtual-listbox.service'; /** * Aria Support for ListBox using a virtual focus with aria-activedescendant */ @Directive({ selector: '[data-gc-virtual-listbox-item]', standalone: false, }) export class VirtualListBoxItemDirective implements OnDestroy { @ContentChildren('gcBadgeRendered') public renderedBadges!: QueryList<BadgeComponent>; @Input('data-gc-virtual-listbox-item') public item!: IndexedItem<unknown>; @Input('ignoreSelection') public ignoreSelection = false; @HostBinding('attr.role') public readonly role = 'option'; @HostBinding('attr.aria-posinset') public ariaPosInSet = 1; @HostBinding('attr.aria-setsize') public ariaSetSize = 1; @HostBinding('class.gc-list-item-focused') public _focused = false; @HostBinding('class.gc-list-item-active') public _active = false; @HostBinding('class.gc-selected') get classSelected(): boolean { return this.selected; } @HostBinding('class.surface-contrast') get classSurfaceSelected(): boolean { return this.selected; } @HostBinding('attr.aria-selected') get ariaSelected(): boolean { return this.selected; } @ContentChild('gcBadge', { read: ElementRef }) public set badge(badge: ElementRef<HTMLElement> | undefined) { this._badge = badge; this.handleBadgeUpdate(); } public get badge() { return this._badge; } @ContentChild('gcIcon') public set icon(icon: ElementRef<HTMLElement> | undefined) { this._icon = icon; } public get icon(): ElementRef<HTMLElement> | undefined { return this._icon; } get key(): Key { return this.item.key; } get selected(): boolean { return this.key == this.vls.value && !this.ignoreSelection; } get index(): number { return this.item.index; } set focused(value: boolean) { this._focused = value; if (value) { this.scrollIntoView(); } } get focused() { return this._focused; } private readonly _activeSubscription: Callback; private _sizeSubscription?: Callback; private _badge?: ElementRef<HTMLElement>; private _icon?: ElementRef<HTMLElement>; constructor( private readonly el: ElementRef<HTMLElement>, private readonly zone: NgZone, private readonly vls: VirtualListboxService, ) { this._activeSubscription = handleActive( el.nativeElement, () => { this._active = true; }, () => { this._active = false; }, ); } @HostListener('click') public _handleClick() { this.vls.selectItem(this.item.item, false); this.vls.updateFocusedIndex(this.item.index); } @HostListener('dblclick') public _handleDoubleClick() { this.vls.selectItem(this.item.item, true); } @HostListener('mousedown') public _handleMouseDown() { this.vls.updateFocusedIndex(this.item.index); } /** @ignore */ ngOnDestroy(): void { this._activeSubscription(); if (this._sizeSubscription) { this._sizeSubscription(); } } updateItem(index: number, size: number): void { this.ariaPosInSet = this.index + 1; this.ariaSetSize = size; } scrollIntoView() { this.el.nativeElement.scrollIntoView({ block: 'nearest', inline: 'nearest', }); } private handleBadgeUpdate() { if (this._sizeSubscription) { this._sizeSubscription(); this._sizeSubscription = undefined; } if (this.badge) { const listResize = observeSize( this.el, this.zone, this.handleResize.bind(this), ); const badgeResize = observeSize( this.el, this.zone, this.handleResize.bind(this), ); this._sizeSubscription = () => { listResize(); badgeResize(); }; } } private handleResize() { if (this.badge) { const badgeWidth = this.badge.nativeElement.clientWidth; const itemWidth = this.el.nativeElement.clientWidth; let availableWidth = itemWidth - 16 * 2; // remove the padding if (this._icon) { availableWidth -= 40; // Bounding Box for Icons availableWidth -= 12; // Space between icon and text } availableWidth -= badgeWidth; availableWidth -= 20; // Margin of the badge if (availableWidth < 160) { this.renderedBadges.forEach(e => (e.allowTextWrap = true)); } else { this.renderedBadges.forEach(e => (e.allowTextWrap = false)); } } } } |