Skip to content
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

Select Content - Allow items to be fixed at top or bottom outside of scrollable element. #400

Open
1 of 2 tasks
CO97 opened this issue Oct 16, 2024 · 0 comments
Open
1 of 2 tasks
Labels
enhancement New feature or request

Comments

@CO97
Copy link

CO97 commented Oct 16, 2024

Which scope/s are relevant/related to the feature request?

select

Information

Allow for elements to be displayed at the start/end of the scrollable dropdown content within the select.

In some scenarios you might want to have content fixed at the top/bottom of the dropdown such as a button or information text.

Example scenario 1:

Showing a summary the number of options available/selected.

Example scenario 2:

Adding a button to reset the select picker.

Describe any alternatives/workarounds you're currently using

Scenario 2;

Usage;

          <brn-select placeholder="Example Select">
                <hlm-select-trigger class="w-48">
                  <hlm-select-value />
                </hlm-select-trigger>
                <hlm-select-content>
                  <div class="max-h-60 overflow-auto">
                    @for (item of items(); track item.id) {
                      <hlm-option [value]="item.id">{{ item.name }}</hlm-option>
                    }
                  </div>
                  <custom-select-reset-button variant="outline">Reset</custom-select-reset-button>
                </hlm-select-content>
              </brn-select>

Reset Button

import {
  ChangeDetectionStrategy,
  Component,
  inject, input
} from '@angular/core';
import { BrnSelectService } from '@spartan-ng/ui-select-brain';
import { HlmButtonDirective } from '@spartan-ng/ui-button-helm';


@Component({
  selector: 'custom-select-reset-button',
  standalone: true,
  host: {
    '(click)': 'onClick()'
  },
  styles: [
    `
      :host {
        width: calc(100% - 0.5rem);
        margin: 0.5rem 0.25rem;
      }
    `
  ],
  template: `
    <ng-content></ng-content>
  `,
  hostDirectives: [{
    directive: HlmButtonDirective,
    inputs: ['variant', 'class']
  }],
  imports: [
    HlmButtonDirective
  ],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class CustomSelectResetButtonComponent {
  private readonly _selectService = inject(BrnSelectService);
  public readonly isExpanded = this._selectService.isExpanded;

  resetValue = input<any>(null);

  public onClick(): void {
    if (!this.isExpanded()) return;

    this._selectService.deselectAllOptions();
    if (this.resetValue()) {
      this._selectService.setInitialSelectedOptions(this.resetValue());
    }

    if (this._selectService.selectTrigger) {
      this._selectService.selectTrigger.focus();
    }

    this._selectService.state.update((state) => ({
      ...state,
      isExpanded: false
    }));
  }
}

I would be willing to submit a PR to fix this issue

  • Yes
  • No
@CO97 CO97 added the enhancement New feature or request label Oct 16, 2024
@CO97 CO97 mentioned this issue Nov 2, 2024
57 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant