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

Fix/person/select/selectedperson clear #1566

Merged
merged 3 commits into from
Aug 12, 2024

Conversation

eikeland
Copy link
Contributor

@eikeland eikeland commented Aug 9, 2024

Fixes clearing selected person when using selectedPerson attribute.

Issue: https://github.com/equinor/fusion/issues/386

Reference AB#55369

File: controller.ts

Summary of Changes:

  1. New Methods Added:
    • clearInput(): Clears the input fields and resets the host's value and search properties.
    • clear(): Calls clearInput(), clears selected IDs, resets the selected person, and dispatches a custom PersonSelectEvent.
    • closeClick(e: MouseEvent | KeyboardEvent): Handles the close icon click event, blurs the input and close icon, closes the dropdown if open, and calls an external close handler if defined.

Detailed Changes:

  1. Method: clearInput()

    • Purpose: Clears the input fields and resets the host's value and search properties.
    • Code:
      public clearInput() {
        this.#host.value = '';
        this.#host.search = '';
        this.#host.textInputElement.value = '';
      }
  2. Method: clear()

    • Purpose: Calls clearInput(), clears selected IDs, resets the selected person, and dispatches a custom PersonSelectEvent.
    • Code:
      public clear() {
        this.clearInput();
      
        if (this.selectedIds.size) {
          this.selectedIds.clear();
        }
      
        if (this.#host.selectedPerson) {
          this.#host.selectedPerson = null;
        }
      
        /* Dispatch custom select event with our details */
        this.#host.dispatchEvent(
          new PersonSelectEvent({
            detail: {
              selected: null,
            },
            bubbles: true,
          }),
        );
      }
  3. Method: closeClick(e: MouseEvent | KeyboardEvent)

    • Purpose: Handles the close icon click event, blurs the input and close icon, closes the dropdown if open, and calls an external close handler if defined.
    • Code:
      public closeClick = (e: MouseEvent | KeyboardEvent): void => {
        if (e.type === 'keydown') {
      
          /* only close on enter or space not tab */
          const me = e as KeyboardEvent;
          if (me.key !== 'Enter' && me.key !== 'Space') {
            return;
          }
      
          /* blur closeicon if focused */
          const closeIcon = this.#host.renderRoot.querySelector('.trailing');
          if (closeIcon) {
            (closeIcon as HTMLSpanElement).blur();
          }
        }
      
        if (this.#host.textInputElement) {
          this.#host.textInputElement.blur();
        }
      
        /* close dropdown if open */
        if (this.isOpen) {
          this.isOpen = false;
        }
      
        /* call resolvers handleclick if defined */
        if (this.#externaCloseHandler) {
          this.#externaCloseHandler(e);
        }
      }

Copy link

changeset-bot bot commented Aug 9, 2024

🦋 Changeset detected

Latest commit: 2d6b8da

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@equinor/fusion-wc-person Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@eikeland eikeland self-assigned this Aug 9, 2024
@eikeland eikeland marked this pull request as draft August 9, 2024 13:57
@eikeland eikeland added bug Something isn't working High priority labels Aug 9, 2024
@eikeland eikeland marked this pull request as ready for review August 9, 2024 13:58
@eikeland eikeland requested a review from a team August 9, 2024 14:01
@eikeland eikeland merged commit 5b61628 into main Aug 12, 2024
7 of 9 checks passed
@eikeland eikeland deleted the fix/person/select/selectedperson-clear branch August 12, 2024 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working High priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants