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: force focus state to dropdown.trigger as document.activeElement stays in body even with clicking #99 #100

Merged
merged 1 commit into from
Dec 27, 2024

Conversation

sun-mota
Copy link
Contributor

@sun-mota sun-mota commented Dec 27, 2024

Related to: AlaskaAirlines/auro-formkit#129

Alaska Airlines Pull Request

Before Submitting this pull request:

  • Link all tickets in this repository related to this PR in the Development section
    note: all pull requests require at least one linked ticket
  • If this PR is Ready For Review, all ticket's linked under Development must have their status changed to Ready For Review as well

By submitting this Pull Request, I confirm that my contribution is made under the terms of the Apache 2.0 license and I have performed a self-review of my own update.

Summary by Sourcery

Fix focus state management in dropdown component to ensure correct element receives focus on click.

Bug Fixes:

  • Fix an issue where clicking the dropdown trigger would not correctly set the focus state, resulting in the document body retaining focus instead of the trigger element.

Enhancements:

  • Update dropdown component to use @floating-ui/dom for improved focus management.

@sun-mota sun-mota self-assigned this Dec 27, 2024
@sun-mota sun-mota requested a review from a team as a code owner December 27, 2024 19:56
Copy link

sourcery-ai bot commented Dec 27, 2024

Reviewer's Guide by Sourcery

This PR fixes a bug where the focus state was not being correctly applied to the dropdown trigger element. The fix forces focus on the trigger element when a click event occurs and the document.activeElement is the body element. This ensures that the dropdown behaves as expected, even when the focus is inadvertently lost.

Sequence diagram for dropdown click event handling with focus fix

sequenceDiagram
    participant User as User
    participant Trigger as Dropdown Trigger
    participant Document as Document
    participant AuroFloatingUI as AuroFloatingUI

    User->>Trigger: Clicks dropdown
    Trigger->>AuroFloatingUI: Triggers click event
    AuroFloatingUI->>Document: Check activeElement
    alt activeElement is body
        AuroFloatingUI->>Trigger: Force focus on trigger
    end
    AuroFloatingUI->>AuroFloatingUI: handleClick()
Loading

State diagram for dropdown focus behavior

stateDiagram-v2
    [*] --> Unfocused
    Unfocused --> FocusedOnBody: Click without proper focus
    FocusedOnBody --> FocusedOnTrigger: Force focus
    Unfocused --> FocusedOnTrigger: Direct focus
    FocusedOnTrigger --> Unfocused: Focus loss
Loading

File-Level Changes

Change Details Files
Force focus on dropdown trigger
  • Added an if statement to check if the active element is the body element. If it is, the focus is set to the current target element.
  • This change ensures that the dropdown trigger element receives focus when clicked, even if the document's active element is the body.
scripts/runtime/floatingUI.mjs
Add floating-ui/dom dependency
  • Added the @floating-ui/dom package to the project dependencies.
  • Updated the package-lock.json file to reflect the new dependency and its version.
package.json
package-lock.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @sun-mota - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Please provide a more detailed PR description explaining the focus management issue being fixed and steps to reproduce the problem.
  • The addition of @floating-ui/dom dependency needs to be explained in the PR description - is this related to the focus fix or addressing a different concern?
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@sun-mota sun-mota merged commit 5bfec7a into main Dec 27, 2024
4 checks passed
@sun-mota sun-mota deleted the sunMota/floatingUI-focus-maintanance branch December 27, 2024 20:13
@blackfalcon
Copy link
Member

🎉 This PR is included in version 3.0.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@blackfalcon blackfalcon added the released Completed work has been released label Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released Completed work has been released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants