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] The new typeahead select implementation is not hiding boilerplate code at all #9511

Closed
KKoukiou opened this issue Aug 17, 2023 · 2 comments
Labels

Comments

@KKoukiou
Copy link
Collaborator

Describe the enhancement or change
The new typeahead requires for the user to implement all the keyboard navigation and generally all event handling manually.

  const handleMenuArrowKeys = (key: string) => {
    let indexToFocus;

    if (isOpen) {
      if (key === 'ArrowUp') {
        // When no index is set or at the first index, focus to the last, otherwise decrement focus index
        if (focusedItemIndex === null || focusedItemIndex === 0) {
          indexToFocus = selectOptions.length - 1;
        } else {
          indexToFocus = focusedItemIndex - 1;
        }
      }

      if (key === 'ArrowDown') {
        // When no index is set or at the last index, focus to the first, otherwise increment focus index
        if (focusedItemIndex === null || focusedItemIndex === selectOptions.length - 1) {
          indexToFocus = 0;
        } else {
          indexToFocus = focusedItemIndex + 1;
        }
      }

      setFocusedItemIndex(indexToFocus);
      const focusedItem = selectOptions.filter((option) => !option.isDisabled)[indexToFocus];
      setActiveItem(`select-multi-typeahead-${focusedItem.value.replace(' ', '-')}`);
    }
  };

  const onInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
    const enabledMenuItems = selectOptions.filter((menuItem) => !menuItem.isDisabled);
    const [firstMenuItem] = enabledMenuItems;
    const focusedItem = focusedItemIndex ? enabledMenuItems[focusedItemIndex] : firstMenuItem;

    switch (event.key) {
      // Select the first available option
      case 'Enter':
        if (!isOpen) {
          setIsOpen((prevIsOpen) => !prevIsOpen);
        } else if (isOpen && focusedItem.value !== 'no results') {
          onSelect(focusedItem.value as string);
        }
        break;
      case 'Tab':
      case 'Escape':
        setIsOpen(false);
        setActiveItem(null);
        break;
      case 'ArrowUp':
      case 'ArrowDown':
        event.preventDefault();
        handleMenuArrowKeys(event.key);
        break;
    }
  };

This is the example code for the keyboard navigation. This code should not be exposed to the developers as it's unlikely that it needs to be changed. Settings the focused and active items should be implemented internally and hidden.

Is this request originating from a Red Hat product team? If so, which ones and is there any sort of deadline for this enhancement?

This is just an ehnancement request and definitely not a blocker. However, for this specific component the developer experience has heavily degraded with the upgrade to Patternfly 5.

@KKoukiou KKoukiou added the DevX label Aug 17, 2023
@github-project-automation github-project-automation bot moved this to Needs triage in PatternFly Issues Aug 17, 2023
KKoukiou added a commit to KKoukiou/anaconda that referenced this issue Aug 17, 2023
As noticed the new Select implementation from PF5 is way more
configurable than the old one but for code readability purposed and
developer experience it is a regression in comparison with the
Patternfly 4 component. [1]

[1] Opened an issue about this upstream: patternfly/patternfly-react#9511
KKoukiou added a commit to KKoukiou/anaconda that referenced this issue Aug 17, 2023
As noticed the new Select implementation from PF5 is way more
configurable than the old one but for code readability purposed and
developer experience it is a regression in comparison with the
Patternfly 4 component. [1]

[1] Opened an issue about this upstream: patternfly/patternfly-react#9511
KKoukiou added a commit to KKoukiou/anaconda that referenced this issue Aug 17, 2023
As noticed the new Select implementation from PF5 is way more
configurable than the old one but for code readability purposed and
developer experience it is a regression in comparison with the
Patternfly 4 component. [1]

[1] Opened an issue about this upstream: patternfly/patternfly-react#9511
KKoukiou added a commit to KKoukiou/anaconda that referenced this issue Aug 17, 2023
As noticed the new Select implementation from PF5 is way more
configurable than the old one but for code readability purposed and
developer experience it is a regression in comparison with the
Patternfly 4 component. [1]

[1] Opened an issue about this upstream: patternfly/patternfly-react#9511
KKoukiou added a commit to KKoukiou/anaconda that referenced this issue Aug 17, 2023
As noticed the new Select implementation from PF5 is way more
configurable than the old one but for code readability purposed and
developer experience it is a regression in comparison with the
Patternfly 4 component. [1]

[1] Opened an issue about this upstream: patternfly/patternfly-react#9511
@wise-king-sullyman wise-king-sullyman moved this from Needs triage to Needs info in PatternFly Issues Aug 29, 2023
@tlabaj tlabaj added this to the Prioritized Backlog milestone Sep 15, 2023
@wise-king-sullyman wise-king-sullyman moved this from Needs info to Not started in PatternFly Issues Oct 4, 2023
@wise-king-sullyman wise-king-sullyman moved this from Not started to In Progress in PatternFly Issues Oct 5, 2023
@kmcfaul kmcfaul moved this from In Progress to Parking lot in PatternFly Issues Oct 12, 2023
KKoukiou added a commit to rhinstaller/anaconda-webui that referenced this issue Nov 8, 2023
As noticed the new Select implementation from PF5 is way more
configurable than the old one but for code readability purposed and
developer experience it is a regression in comparison with the
Patternfly 4 component. [1]

[1] Opened an issue about this upstream: patternfly/patternfly-react#9511
Copy link

stale bot commented Jan 14, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the wontfix label Jan 14, 2024
@tlabaj tlabaj modified the milestones: 2023.Q4, Prioritized Backlog Jan 16, 2024
@stale stale bot removed the wontfix label Jan 16, 2024
Copy link

stale bot commented Mar 16, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the wontfix label Mar 16, 2024
@stale stale bot closed this as completed Apr 18, 2024
@github-project-automation github-project-automation bot moved this from Parking lot to Done in PatternFly Issues Apr 18, 2024
@tlabaj tlabaj removed this from the Prioritized Backlog milestone Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants