@ship-ui/core 0.15.23 → 0.15.24

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.
@@ -3593,6 +3593,7 @@ function observeChildren(parentEl, elementTags) {
3593
3593
 
3594
3594
  class ShipMenuComponent {
3595
3595
  constructor() {
3596
+ this.#document = inject(DOCUMENT);
3596
3597
  this.#renderer = inject(Renderer2);
3597
3598
  this.asMultiLayer = input(false, ...(ngDevMode ? [{ debugName: "asMultiLayer" }] : []));
3598
3599
  this.openIndicator = input(false, ...(ngDevMode ? [{ debugName: "openIndicator" }] : []));
@@ -3611,17 +3612,26 @@ class ShipMenuComponent {
3611
3612
  this.inputValue = createInputSignal(this.inputRef);
3612
3613
  this.abortController = null;
3613
3614
  this.optionsEffect = effect(() => {
3614
- if (!this.isOpen())
3615
- return;
3616
- if (this.abortController) {
3615
+ if (this.abortController !== null) {
3617
3616
  this.abortController.abort();
3618
3617
  this.abortController = null;
3619
3618
  }
3619
+ if (!this.isOpen())
3620
+ return;
3620
3621
  this.abortController = new AbortController();
3622
+ const searchable = this.searchable();
3623
+ if (!searchable) {
3624
+ this.#document.documentElement.addEventListener('keydown', this.keyDownEventListener, {
3625
+ signal: this.abortController.signal,
3626
+ });
3627
+ }
3621
3628
  const inputEl = this.inputRef()?.nativeElement;
3622
3629
  if (!inputEl)
3623
3630
  return;
3624
3631
  queueMicrotask(() => inputEl.focus());
3632
+ inputEl.addEventListener('keydown', this.keyDownEventListener, {
3633
+ signal: this.abortController.signal,
3634
+ });
3625
3635
  if (!this.closeOnClick()) {
3626
3636
  const optionRef = this.optionsRef()?.nativeElement;
3627
3637
  optionRef?.addEventListener('click', (e) => {
@@ -3639,31 +3649,29 @@ class ShipMenuComponent {
3639
3649
  }
3640
3650
  });
3641
3651
  }
3642
- inputEl.addEventListener('keydown', (e) => {
3643
- const activeOptionIndex = this.activeOptionIndex();
3644
- if (e.key === 'ArrowDown') {
3645
- e.preventDefault();
3646
- this.activeOptionIndex.set(this.nextActiveIndex(activeOptionIndex));
3647
- }
3648
- else if (e.key === 'ArrowUp') {
3649
- e.preventDefault();
3650
- this.activeOptionIndex.set(this.prevActiveIndex(activeOptionIndex));
3651
- }
3652
- else if (e.key === 'Enter') {
3653
- e.preventDefault();
3654
- if (activeOptionIndex > -1) {
3655
- this.activeElements()[activeOptionIndex].click();
3656
- queueMicrotask(() => this.close('active'));
3657
- }
3658
- }
3659
- else if (e.key === 'Tab') {
3660
- e.preventDefault();
3661
- this.close('closed');
3662
- }
3663
- }, {
3664
- signal: this.abortController.signal,
3665
- });
3666
3652
  }, ...(ngDevMode ? [{ debugName: "optionsEffect" }] : []));
3653
+ this.keyDownEventListener = (e) => {
3654
+ const activeOptionIndex = this.activeOptionIndex();
3655
+ if (e.key === 'ArrowDown') {
3656
+ e.preventDefault();
3657
+ this.activeOptionIndex.set(this.nextActiveIndex(activeOptionIndex));
3658
+ }
3659
+ else if (e.key === 'ArrowUp') {
3660
+ e.preventDefault();
3661
+ this.activeOptionIndex.set(this.prevActiveIndex(activeOptionIndex));
3662
+ }
3663
+ else if (e.key === 'Enter') {
3664
+ e.preventDefault();
3665
+ if (activeOptionIndex > -1) {
3666
+ this.activeElements()[activeOptionIndex].click();
3667
+ queueMicrotask(() => this.close('active'));
3668
+ }
3669
+ }
3670
+ else if (e.key === 'Tab') {
3671
+ e.preventDefault();
3672
+ this.close('closed');
3673
+ }
3674
+ };
3667
3675
  this._lastElementList = [];
3668
3676
  this.activeElements = signal([], ...(ngDevMode ? [{ debugName: "activeElements" }] : []));
3669
3677
  this.lastInputValue = '';
@@ -3673,6 +3681,15 @@ class ShipMenuComponent {
3673
3681
  return;
3674
3682
  const inputValue = (this.inputValue() ?? '').toLowerCase();
3675
3683
  this.#resetActiveOption();
3684
+ if (!inputValue || inputValue === '') {
3685
+ const allOptions = this.optionsEl();
3686
+ this.activeElements.set(allOptions);
3687
+ this._lastElementList = allOptions;
3688
+ for (let i = 0; i < allOptions.length; i++) {
3689
+ this.#renderer.removeStyle(allOptions[i], 'order');
3690
+ }
3691
+ return;
3692
+ }
3676
3693
  if (!inputValue || inputValue === '')
3677
3694
  return;
3678
3695
  let optionElements = this._lastElementList.length && inputValue.length > this.lastInputValue.length
@@ -3706,6 +3723,7 @@ class ShipMenuComponent {
3706
3723
  }
3707
3724
  }, ...(ngDevMode ? [{ debugName: "activeOptionIndexEffect" }] : []));
3708
3725
  }
3726
+ #document;
3709
3727
  #renderer;
3710
3728
  toggleIsOpen(event) {
3711
3729
  event.preventDefault();