@spartan-ng/brain 1.5.0-beta.5 → 1.5.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,14 @@
1
1
  import { ActiveDescendantKeyManager } from '@angular/cdk/a11y';
2
2
  import * as i0 from '@angular/core';
3
- import { InjectionToken, inject, ElementRef, computed, Directive, forwardRef, Injector, input, booleanAttribute, linkedSignal, model, signal, contentChildren, contentChild, afterNextRender, effect, untracked, Renderer2, TemplateRef, ViewContainerRef, PLATFORM_ID } from '@angular/core';
3
+ import { InjectionToken, inject, ElementRef, input, computed, Directive, forwardRef, Injector, booleanAttribute, linkedSignal, model, signal, contentChildren, contentChild, afterNextRender, effect, untracked, Renderer2, TemplateRef, ViewContainerRef, PLATFORM_ID } from '@angular/core';
4
4
  import { NG_VALUE_ACCESSOR } from '@angular/forms';
5
5
  import * as i1 from '@spartan-ng/brain/field';
6
6
  import { BrnFieldControl, provideBrnLabelable } from '@spartan-ng/brain/field';
7
7
  import { BrnPopover } from '@spartan-ng/brain/popover';
8
8
  import { stringifyAsLabel, injectElementSize } from '@spartan-ng/brain/core';
9
9
  import { BrnOverlay } from '@spartan-ng/brain/overlay';
10
+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
11
+ import { startWith } from 'rxjs/operators';
10
12
  import { isPlatformBrowser } from '@angular/common';
11
13
 
12
14
  const comboboxContainsFilter = (item, query, collator, itemToString) => {
@@ -72,26 +74,30 @@ function injectBrnComboboxConfig() {
72
74
  }
73
75
 
74
76
  class BrnComboboxContent {
77
+ static _id = 0;
75
78
  _combobox = injectBrnComboboxBase();
76
79
  el = inject(ElementRef);
80
+ /** The id of the combobox content */
81
+ id = input(`brn-combobox-content-${++BrnComboboxContent._id}`, ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
77
82
  _dataState = computed(() => (this._combobox.isExpanded() ? 'open' : 'closed'), ...(ngDevMode ? [{ debugName: "_dataState" }] : /* istanbul ignore next */ []));
78
83
  /** Determine if the combobox has no visible items */
79
84
  _isEmpty = computed(() => !this._combobox.visibleItems(), ...(ngDevMode ? [{ debugName: "_isEmpty" }] : /* istanbul ignore next */ []));
80
85
  _comboboxWidth = this._combobox.searchInputWrapperWidth;
81
86
  /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnComboboxContent, deps: [], target: i0.ɵɵFactoryTarget.Directive });
82
- /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.16", type: BrnComboboxContent, isStandalone: true, selector: "[brnComboboxContent]", host: { properties: { "attr.data-state": "_dataState()", "attr.data-empty": "_isEmpty() ? \"\" : null", "style.--brn-combobox-width.px": "_comboboxWidth()" } }, ngImport: i0 });
87
+ /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.16", type: BrnComboboxContent, isStandalone: true, selector: "[brnComboboxContent]", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "id": "id()", "attr.data-state": "_dataState()", "attr.data-empty": "_isEmpty() ? \"\" : null", "style.--brn-combobox-width.px": "_comboboxWidth()" } }, ngImport: i0 });
83
88
  }
84
89
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnComboboxContent, decorators: [{
85
90
  type: Directive,
86
91
  args: [{
87
92
  selector: '[brnComboboxContent]',
88
93
  host: {
94
+ '[id]': 'id()',
89
95
  '[attr.data-state]': '_dataState()',
90
96
  '[attr.data-empty]': '_isEmpty() ? "" : null',
91
97
  '[style.--brn-combobox-width.px]': '_comboboxWidth()',
92
98
  },
93
99
  }]
94
- }] });
100
+ }], propDecorators: { id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }] } });
95
101
 
96
102
  const BrnComboboxItemToken = new InjectionToken('BrnComboboxItemToken');
97
103
  function provideBrnComboboxItem(comboboxItem) {
@@ -160,6 +166,8 @@ class BrnCombobox {
160
166
  _comboboxList = signal(undefined, ...(ngDevMode ? [{ debugName: "_comboboxList" }] : /* istanbul ignore next */ []));
161
167
  /** @internal The id of the combobox list, registered by BrnComboboxList. Used by the input for aria-controls. */
162
168
  listId = computed(() => this._comboboxList()?.id(), ...(ngDevMode ? [{ debugName: "listId" }] : /* istanbul ignore next */ []));
169
+ /** @internal The id of the combobox content. Used by the trigger for aria-controls. */
170
+ contentId = computed(() => this._content()?.id(), ...(ngDevMode ? [{ debugName: "contentId" }] : /* istanbul ignore next */ []));
163
171
  mode = computed(() => this._comboboxInput()?.mode() || 'combobox', ...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
164
172
  labelableId = computed(() => this._comboboxInput()?.id(), ...(ngDevMode ? [{ debugName: "labelableId" }] : /* istanbul ignore next */ []));
165
173
  _onChange;
@@ -576,6 +584,7 @@ class BrnComboboxInput {
576
584
  disabled = this._combobox.disabledState;
577
585
  /** Whether the combobox panel is expanded */
578
586
  _isExpanded = this._combobox.isExpanded;
587
+ _activeDescendant = signal(undefined, ...(ngDevMode ? [{ debugName: "_activeDescendant" }] : /* istanbul ignore next */ []));
579
588
  /** Computed aria-invalid: uses manual override if provided, otherwise reads from parent error state. */
580
589
  _ariaInvalid = computed(() => this.ariaInvalidOverride() ?? this._combobox.controlState?.()?.invalid, ...(ngDevMode ? [{ debugName: "_ariaInvalid" }] : /* istanbul ignore next */ []));
581
590
  _dirty = computed(() => this._combobox.controlState?.()?.dirty, ...(ngDevMode ? [{ debugName: "_dirty" }] : /* istanbul ignore next */ []));
@@ -584,6 +593,11 @@ class BrnComboboxInput {
584
593
  _isCombobox = computed(() => this.mode() === 'combobox', ...(ngDevMode ? [{ debugName: "_isCombobox" }] : /* istanbul ignore next */ []));
585
594
  constructor() {
586
595
  this._combobox.registerComboboxInput?.(this);
596
+ this._combobox.keyManager.change
597
+ .pipe(startWith(this._combobox.keyManager.activeItemIndex), takeUntilDestroyed())
598
+ .subscribe(() => {
599
+ this._activeDescendant.set(this._combobox.keyManager.activeItem?.id());
600
+ });
587
601
  effect(() => {
588
602
  const value = this._combobox.value();
589
603
  const search = this._combobox.search();
@@ -643,7 +657,7 @@ class BrnComboboxInput {
643
657
  this._combobox.keyManager.onKeydown(event);
644
658
  }
645
659
  /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnComboboxInput, deps: [], target: i0.ɵɵFactoryTarget.Directive });
646
- /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.16", type: BrnComboboxInput, isStandalone: true, selector: "input[brnComboboxInput]", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, ariaInvalidOverride: { classPropertyName: "ariaInvalidOverride", publicName: "aria-invalid", isSignal: true, isRequired: false, transformFunction: null }, forceInvalid: { classPropertyName: "forceInvalid", publicName: "forceInvalid", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "type": "text", "role": "combobox", "autocomplete": "off", "autocorrect": "off", "autocapitalize": "none", "spellcheck": "false", "aria-autocomplete": "list", "aria-haspopup": "listbox" }, listeners: { "keydown": "onKeyDown($event)", "input": "onInput($event)" }, properties: { "id": "id()", "attr.aria-expanded": "_isExpanded()", "attr.aria-controls": "_comboboxListId()", "attr.aria-invalid": "_isCombobox() && _ariaInvalid() ? \"true\": null", "attr.data-invalid": "_isCombobox() && _ariaInvalid() ? \"true\": null", "attr.data-matches-spartan-invalid": "_isCombobox() && _spartanInvalid() ? \"true\": null", "attr.data-touched": "_isCombobox() && _touched() ? \"true\": null", "attr.data-dirty": "_isCombobox() && _dirty() ? \"true\": null", "attr.disabled": "disabled() ? \"\" : null" } }, exportAs: ["brnComboboxInput"], ngImport: i0 });
660
+ /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.16", type: BrnComboboxInput, isStandalone: true, selector: "input[brnComboboxInput]", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, ariaInvalidOverride: { classPropertyName: "ariaInvalidOverride", publicName: "aria-invalid", isSignal: true, isRequired: false, transformFunction: null }, forceInvalid: { classPropertyName: "forceInvalid", publicName: "forceInvalid", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "type": "text", "role": "combobox", "autocomplete": "off", "autocorrect": "off", "autocapitalize": "none", "spellcheck": "false", "aria-autocomplete": "list", "aria-haspopup": "listbox" }, listeners: { "keydown": "onKeyDown($event)", "input": "onInput($event)" }, properties: { "id": "id()", "attr.aria-expanded": "_isExpanded()", "attr.aria-controls": "_isExpanded() ? _comboboxListId() : null", "attr.aria-activedescendant": "_isExpanded() ? _activeDescendant() : null", "attr.aria-invalid": "_isCombobox() && _ariaInvalid() ? \"true\": null", "attr.data-invalid": "_isCombobox() && _ariaInvalid() ? \"true\": null", "attr.data-matches-spartan-invalid": "_isCombobox() && _spartanInvalid() ? \"true\": null", "attr.data-touched": "_isCombobox() && _touched() ? \"true\": null", "attr.data-dirty": "_isCombobox() && _dirty() ? \"true\": null", "attr.disabled": "disabled() ? \"\" : null" } }, exportAs: ["brnComboboxInput"], ngImport: i0 });
647
661
  }
648
662
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnComboboxInput, decorators: [{
649
663
  type: Directive,
@@ -661,7 +675,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImpo
661
675
  'aria-autocomplete': 'list',
662
676
  'aria-haspopup': 'listbox',
663
677
  '[attr.aria-expanded]': '_isExpanded()',
664
- '[attr.aria-controls]': '_comboboxListId()',
678
+ '[attr.aria-controls]': '_isExpanded() ? _comboboxListId() : null',
679
+ '[attr.aria-activedescendant]': '_isExpanded() ? _activeDescendant() : null',
665
680
  '[attr.aria-invalid]': '_isCombobox() && _ariaInvalid() ? "true": null',
666
681
  '[attr.data-invalid]': '_isCombobox() && _ariaInvalid() ? "true": null',
667
682
  '[attr.data-matches-spartan-invalid]': '_isCombobox() && _spartanInvalid() ? "true": null',
@@ -847,6 +862,8 @@ class BrnComboboxMultiple {
847
862
  _comboboxList = signal(undefined, ...(ngDevMode ? [{ debugName: "_comboboxList" }] : /* istanbul ignore next */ []));
848
863
  /** @internal The id of the combobox list, registered by BrnComboboxList. Used by the input for aria-controls. */
849
864
  listId = computed(() => this._comboboxList()?.id(), ...(ngDevMode ? [{ debugName: "listId" }] : /* istanbul ignore next */ []));
865
+ /** @internal The id of the combobox content. Used by the trigger for aria-controls. */
866
+ contentId = computed(() => this._content()?.id(), ...(ngDevMode ? [{ debugName: "contentId" }] : /* istanbul ignore next */ []));
850
867
  mode = signal('combobox').asReadonly();
851
868
  labelableId = computed(() => this._comboboxChipInput()?.id(), ...(ngDevMode ? [{ debugName: "labelableId" }] : /* istanbul ignore next */ []));
852
869
  _onChange;
@@ -1084,6 +1101,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImpo
1084
1101
  class BrnComboboxTrigger {
1085
1102
  _combobox = injectBrnComboboxBase();
1086
1103
  _isExpanded = this._combobox.isExpanded;
1104
+ /** The id of the combobox content, used for aria-controls. */
1105
+ _contentId = this._combobox.contentId;
1087
1106
  _disabled = this._combobox.disabledState;
1088
1107
  _isPlaceholder = computed(() => !this._combobox.hasValue(), ...(ngDevMode ? [{ debugName: "_isPlaceholder" }] : /* istanbul ignore next */ []));
1089
1108
  _ariaInvalid = computed(() => this._combobox.controlState?.()?.invalid, ...(ngDevMode ? [{ debugName: "_ariaInvalid" }] : /* istanbul ignore next */ []));
@@ -1098,7 +1117,7 @@ class BrnComboboxTrigger {
1098
1117
  }
1099
1118
  }
1100
1119
  /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnComboboxTrigger, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1101
- /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.16", type: BrnComboboxTrigger, isStandalone: true, selector: "button[brnComboboxTrigger]", inputs: { forceInvalid: { classPropertyName: "forceInvalid", publicName: "forceInvalid", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "type": "button", "role": "combobox", "aria-haspopup": "dialog" }, listeners: { "keydown": "onKeyDown($event)" }, properties: { "attr.aria-expanded": "_isExpanded() ? \"true\" : \"false\"", "attr.aria-disabled": "_disabled() ? \"true\" : null", "attr.disabled": "_disabled() ? \"\" : null", "attr.data-placeholder": "_isPlaceholder() ? \"\" : null", "attr.aria-invalid": " _ariaInvalid() ? \"true\": null", "attr.data-invalid": " _ariaInvalid() ? \"true\": null", "attr.data-matches-spartan-invalid": " _spartanInvalid() ? \"true\": null", "attr.data-touched": " _touched() ? \"true\": null", "attr.data-dirty": " _dirty() ? \"true\": null" } }, ngImport: i0 });
1120
+ /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.16", type: BrnComboboxTrigger, isStandalone: true, selector: "button[brnComboboxTrigger]", inputs: { forceInvalid: { classPropertyName: "forceInvalid", publicName: "forceInvalid", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "type": "button", "role": "combobox", "aria-haspopup": "dialog" }, listeners: { "keydown": "onKeyDown($event)" }, properties: { "attr.aria-controls": "_isExpanded() ? _contentId() : null", "attr.aria-expanded": "_isExpanded()", "attr.aria-disabled": "_disabled() || null", "attr.disabled": "_disabled() ? \"\" : null", "attr.data-disabled": "_disabled() || null", "attr.data-placeholder": "_isPlaceholder() ? \"\" : null", "attr.aria-invalid": " _ariaInvalid() ? \"true\": null", "attr.data-invalid": " _ariaInvalid() ? \"true\": null", "attr.data-matches-spartan-invalid": " _spartanInvalid() ? \"true\": null", "attr.data-touched": " _touched() ? \"true\": null", "attr.data-dirty": " _dirty() ? \"true\": null" } }, ngImport: i0 });
1102
1121
  }
1103
1122
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnComboboxTrigger, decorators: [{
1104
1123
  type: Directive,
@@ -1108,9 +1127,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImpo
1108
1127
  type: 'button',
1109
1128
  role: 'combobox',
1110
1129
  'aria-haspopup': 'dialog',
1111
- '[attr.aria-expanded]': '_isExpanded() ? "true" : "false"',
1112
- '[attr.aria-disabled]': '_disabled() ? "true" : null',
1130
+ '[attr.aria-controls]': '_isExpanded() ? _contentId() : null',
1131
+ '[attr.aria-expanded]': '_isExpanded()',
1132
+ '[attr.aria-disabled]': '_disabled() || null',
1113
1133
  '[attr.disabled]': '_disabled() ? "" : null',
1134
+ '[attr.data-disabled]': '_disabled() || null',
1114
1135
  '[attr.data-placeholder]': '_isPlaceholder() ? "" : null',
1115
1136
  '[attr.aria-invalid]': ' _ariaInvalid() ? "true": null',
1116
1137
  '[attr.data-invalid]': ' _ariaInvalid() ? "true": null',