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 #3

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

Review Considerations

This PR includes changes that alter the current:

  • UI/UX
  • Accessibility (a11y) support

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 Floating UI with a new dropdown component as a proof of concept, introducing 'auro-dropdown' and 'MySelect' components, along with supporting styles and documentation.

New Features:

  • Introduce a new custom element 'auro-dropdown' that provides a trigger and dropdown element combination for interactive dropdown content.
  • Add 'MySelect' component that utilizes 'auro-dropdown' for creating a dropdown with a select input.
  • Implement 'AuroFloatingUI' class to manage the positioning and visibility of dropdown elements using Floating UI.

Enhancements:

  • Integrate design tokens and styles for the new dropdown components to ensure consistent theming and styling.

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:22
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 bib (popover) component, and integration with FloatingUI for positioning. The PR also adds necessary styles, documentation, and example usage.

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 hoverToggle
        +Boolean noToggle
        +Boolean focusShow
        +Boolean noHideOnThisFocusLoss
        +Boolean isPopoverVisible
        +Number dropdownWidth
        +String placement
        +Number tabIndex
        +Function onSlotChange
        +AuroLibraryRuntimeUtils runtimeUtils
        +AuroFloatingUI floater
        +Object floaterConfig
        +String iconTag
        +void privateDefaults()
        +void connectedCallback()
        +void disconnectedCallback()
        +void updated(changedProperties)
        +void firstUpdated()
        +void handleDefaultSlot()
        +html 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 --> AuroFloatingUI
    AuroDropdown --> AuroDropdownBib
    AuroDropdown --> AuroLibraryRuntimeUtils
    AuroDropdown --> AuroDependencyVersioning
    AuroDropdown --> AuroIcon
    AuroDropdown --> AuroDropdownBib
    AuroDropdown --> AuroFloatingUI
    AuroDropdown --> AuroLibraryRuntimeUtils
    AuroDropdown --> AuroDependencyVersioning
    AuroDropdown --> AuroIcon

    class AuroDropdownBib {
        +html render()
    }

    class MySelect {
        +String value
        +void configureBibContent()
        +void firstUpdated()
        +void updated(changedProperties)
        +html render()
    }

    MySelect --> AuroDropdown
    AuroDropdown --> AuroDropdownBib
    AuroDropdown --> AuroFloatingUI
    AuroDropdown --> AuroLibraryRuntimeUtils
    AuroDropdown --> AuroDependencyVersioning
    AuroDropdown --> AuroIcon

    class AuroLibraryRuntimeUtils {
    }

    class AuroDependencyVersioning {
        +String generateTag(componentName, version, component)
    }

    class AuroIcon {
    }
Loading

File-Level Changes

Change Details Files
Implement auro-dropdown custom element
  • Create main AuroDropdown class with properties and methods
  • Implement render function for dropdown structure
  • Add event listeners for various interactions (click, hover, focus)
  • Integrate with FloatingUI for positioning
src/dropdown/auro-dropdown.js
Create AuroDropdownBib component for popover content
  • Implement AuroDropdownBib class
  • Add render function for bib content
src/dropdown/auro-dropdownBib.js
Implement FloatingUI integration
  • Create AuroFloatingUI class with positioning and state management methods
  • Implement show/hide functionality for the dropdown
src/dropdown/floatingUI.mjs
Add styles for dropdown and bib components
  • Create SCSS files for layout, color, and token styles
  • Implement responsive design and accessibility features
src/dropdown/style.scss
src/dropdown/color.scss
src/dropdown/tokens.scss
src/dropdown/bibStyles.scss
Add documentation and demo
  • Create README with component description, installation instructions, and API examples
  • Add demo page with basic usage examples
README.md
demo/index.md
Implement example select component using auro-dropdown
  • Create MySelect class extending auro-dropdown functionality
  • Add value property and event listener for input changes
src/dropdown/select.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

@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

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 - here's some feedback:

Overall Comments:

  • Consider adding unit tests for this new component to ensure reliability and ease future maintenance.
  • There's a significant amount of commented-out code and TODO comments. Please clean these up before merging to improve code readability.
Here's what I looked at during the review
  • 🟡 General issues: 2 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.

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 content is automatically added from ./../docs/partials/description.md -->
`<auro-form>` is a [HTML custom element](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements) for the purpose of ...

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam convallis in tellus nec pellentesque. Integer bibendum ligula sit amet vehicula gravida. Maecenas accumsan, ligula vitae molestie iaculis, tellus mi laoreet ex [install instructions](https://auro.alaskaair.com/components/auro/button/install), ac malesuada velit dolor vel mi. Cras et rutrum urna. Sed mattis mi eu tortor ullamcorper, egestas bibendum mauris cursus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus viverra eros eget neque commodo vulputate. In tempus eu velit at dictum.
Copy link

Choose a reason for hiding this comment

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

issue (documentation): Typo: Repeated 'the' in the description

There's a small typo in the description. 'the the' is repeated in the sentence 'This file is generated based on a template fetched from the the docs are compiled.'

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