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

feat: initial integration of floatingUI and dropdown POC #4

Closed
wants to merge 1 commit into from

Conversation

jason-capsule42
Copy link
Member

@jason-capsule42 jason-capsule42 commented Oct 3, 2024

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

Integrate FloatingUI and introduce a new dropdown component as a proof of concept. The 'auro-dropdown' component is designed to be interactive and customizable, supporting various features like chevron display and event-driven visibility toggling. Additionally, a 'MySelect' component is added to demonstrate the dropdown's usage in a selectable input context. Documentation is provided to guide users on installation and usage.

New Features:

  • Introduce a new custom element 'auro-dropdown' that provides a dropdown component with various interactive features such as chevron display, border options, and event handling for visibility toggling.
  • Add 'MySelect' component that utilizes 'auro-dropdown' to create a selectable input interface with event-driven value updates.

Enhancements:

  • Integrate FloatingUI for positioning and managing dropdown visibility, enhancing the dropdown's responsiveness to user interactions and environmental changes.

Documentation:

  • Add a README.md file with detailed documentation on the new dropdown component, including installation instructions, usage examples, and development guidelines.

@jason-capsule42 jason-capsule42 requested a review from a team as a code owner October 3, 2024 03:40
Copy link

sourcery-ai bot commented Oct 3, 2024

Reviewer's Guide by Sourcery

This pull request introduces a new auro-dropdown component, which is a customizable dropdown element for interactive content. The implementation includes the main dropdown component, a separate bib (dropdown content) component, and integration with the FloatingUI library for positioning. The PR also includes necessary styles, documentation, and example usage.

Sequence diagram for auro-dropdown interactions

sequenceDiagram
    actor User
    participant AuroDropdown
    participant AuroFloatingUI
    participant AuroDropdownBib

    User->>AuroDropdown: Click on trigger
    AuroDropdown->>AuroFloatingUI: handleClick()
    AuroFloatingUI->>AuroDropdown: showBib()
    AuroDropdown->>AuroDropdownBib: Display dropdown content
    AuroFloatingUI->>AuroDropdown: setupHideHandlers()
    User->>AuroDropdown: Click outside
    AuroFloatingUI->>AuroDropdown: hideBib()
    AuroDropdown->>AuroDropdownBib: Hide dropdown content
Loading

Class diagram for the new auro-dropdown component

classDiagram
    class AuroDropdown {
        +Boolean bordered
        +Boolean chevron
        +Boolean disabled
        +Boolean error
        +Boolean inset
        +Boolean matchWidth
        +Boolean rounded
        +Boolean noToggle
        +Boolean noHideOnThisFocusLoss
        +Boolean isPopoverVisible
        +Boolean ready
        +Number dropdownWidth
        +String placement
        +Number tabIndex
        +void privateDefaults()
        +void connectedCallback()
        +void disconnectedCallback()
        +void updated(changedProperties)
        +void firstUpdated()
        +void handleDefaultSlot()
        +render()
    }

    class AuroDropdownBib {
        +render()
    }

    class AuroFloatingUI {
        +void position()
        +void updateState()
        +void setupHideHandlers()
        +void handleUpdate(changedProperties)
        +void updateCurrentExpandedDropdown()
        +void showBib()
        +void hideBib()
        +void handleClick()
        +void handleEvent(event)
        +void handleTriggerTabIndex()
        +void configure(elem)
    }

    AuroDropdown --> AuroDropdownBib
    AuroDropdown --> AuroFloatingUI
Loading

File-Level Changes

Change Details Files
Implement main auro-dropdown component
  • Create AuroDropdown class extending LitElement
  • Implement render method for dropdown structure
  • Add properties for customization (e.g., bordered, chevron, disabled)
  • Integrate with FloatingUI for positioning
  • Implement show/hide functionality
src/dropdown/auro-dropdown.js
Create separate auro-dropdownBib component for dropdown content
  • Implement AuroDropdownBib class extending LitElement
  • Create render method for bib content
src/dropdown/auro-dropdownBib.js
Implement FloatingUI integration
  • Create AuroFloatingUI class for handling positioning
  • Implement methods for showing, hiding, and updating dropdown position
src/dropdown/floatingUI.mjs
Add styles for dropdown component
  • Create main styles for dropdown layout
  • Implement color styles for different states
  • Add token styles for customization
src/dropdown/style.scss
src/dropdown/color.scss
src/dropdown/tokens.scss
Create example select component using auro-dropdown
  • Implement MySelect class extending LitElement
  • Use auro-dropdown in render method
  • Add value property and event listener for input changes
src/dropdown/select.js
Update project configuration and documentation
  • Add README.md with component description and usage instructions
  • Create demo/index.md for component demonstration
  • Update index.js to export new components
README.md
demo/index.md
index.js

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.

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 @jason-capsule42 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟡 Documentation: 1 issue found

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.

// this.dispatchEvent(event);
// }

// applyBibContentFunctionality(bibElem) {
Copy link

Choose a reason for hiding this comment

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

suggestion: Remove or uncomment and use commented-out code

There are several blocks of commented-out code in this file. If this code is no longer needed, it should be removed. If it's still needed, it should be uncommented and used. Keeping commented-out code can lead to confusion and maintenance issues.

Suggested change
// applyBibContentFunctionality(bibElem) {
applyBibContentFunctionality(bibElem) {
if (bibElem) {
// Implementation goes here
}
}

try {
this.element.cleanup();
// this.element.bib.remove(); // is this doing anything? Seems like it's doing the wrong thing
} catch (error) {
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Improve error handling in catch blocks

Several catch blocks in the code are empty or only contain a comment. Consider logging these errors or handling them appropriately to avoid masking important issues.

Suggested change
} catch (error) {
} catch (error) {
console.warn('Error during element cleanup:', error);
}

* @event auroDropdown-ready - Notifies that the component has finished initializing.
* @event auroDropdown-toggled - Notifies that the visibility of the dropdown bib has changed.
*/
export class AuroDropdown extends LitElement {
Copy link

Choose a reason for hiding this comment

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

suggestion: Enhance accessibility features of the dropdown component

Ensure that the dropdown component is fully accessible. This includes making it keyboard navigable, ensuring it works well with screen readers, and following ARIA best practices for dropdown menus. Consider adding appropriate ARIA attributes and roles.

export class AuroDropdown extends LitElement {
  static get properties() {
    return {
      expanded: { type: Boolean, reflect: true },
      label: { type: String }
    };
  }

  constructor() {
    super();
    this.expanded = false;
    this.addEventListener('keydown', this._handleKeyDown);
  }

<!-- The below code snippet is automatically added from ./../apiExamples/basic.html -->

```html
<auro-form>Hello World</auro-form>
Copy link

Choose a reason for hiding this comment

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

question (documentation): Consider additional API examples

Are there other use cases or configurations of the component that could be showcased here? Additional examples could help users understand the full capabilities of the component.

import { AuroDropdown } from "./auro-dropdown.js";


export class MySelect extends LitElement {
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider extending AuroDropdown instead of creating a new component.

The MySelect component introduces an unnecessary layer of abstraction by wrapping AuroDropdown. Consider extending AuroDropdown instead of creating a new component. This would simplify the code and reduce complexity while maintaining the desired functionality. Here's a suggested approach:

import { AuroDropdown } from "./auro-dropdown.js";

export class MySelect extends AuroDropdown {
  static get properties() {
    return {
      ...super.properties,
      value: {
        type: String,
        reflect: true
      }
    };
  }

  firstUpdated(changedProperties) {
    super.firstUpdated(changedProperties);
    this.configureBibContent();
  }

  configureBibContent() {
    try {
      this.inputElement = this.bibContent.querySelector('#selectInput');
      this.inputElement.addEventListener('input', (event) => {
        this.value = event.target.value;
      });
    } catch (error) {
      // Handle error
    }
  }

  updated(changedProperties) {
    super.updated(changedProperties);
    if (changedProperties.has('value')) {
      console.warn('select.value updated to', this.value);
    }
  }
}

if (!customElements.get("my-select")) {
  customElements.define("my-select", MySelect);
}

This approach extends AuroDropdown, eliminating the need for a separate wrapper component. It maintains the custom value property and the configureBibContent method while leveraging the existing functionality of AuroDropdown.

If there are specific reasons for the current implementation that require a separate component, please clarify these requirements so we can suggest a more tailored solution.

Comment on lines +58 to +62
if (!this.element.noHideOnThisFocusLoss && !this.element.hasAttribute('noHideOnThisFocusLoss')) { // is this the right place to do this?
if (document.activeElement !== document.querySelector('body') && !this.element.contains(document.activeElement) && !this.element.bibContent.contains(document.activeElement)) {
this.hideBib();
}
}
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Merge nested if conditions (merge-nested-ifs)

Suggested change
if (!this.element.noHideOnThisFocusLoss && !this.element.hasAttribute('noHideOnThisFocusLoss')) { // is this the right place to do this?
if (document.activeElement !== document.querySelector('body') && !this.element.contains(document.activeElement) && !this.element.bibContent.contains(document.activeElement)) {
this.hideBib();
}
}
if (!this.element.noHideOnThisFocusLoss && !this.element.hasAttribute('noHideOnThisFocusLoss') && (document.activeElement !== document.querySelector('body') && !this.element.contains(document.activeElement) && !this.element.bibContent.contains(document.activeElement))) {
this.hideBib();
}


ExplanationReading deeply nested conditional code is confusing, since you have to keep track of which
conditions relate to which levels. We therefore strive to reduce nesting where
possible, and the situation where two if conditions can be combined using
and is an easy win.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant