+
Skip to content
This repository was archived by the owner on Oct 14, 2025. It is now read-only.

Conversation

clintcs
Copy link
Collaborator

@clintcs clintcs commented Nov 8, 2024

🚀 Description

@ynotdraw were chatting about the asynchronous filtering case, which we hadn't been forced to think through until now. We realized that Dropdown doesn't handle that case and has other issues.

Dropdown currently dispatches a "filter" event on "input". The idea is that consumers can listen for that event and then decide to render or not render certain options.

One problem with that approach is multiselect Dropdown has a tag for each selected option, and Dropdown relies on those selected options being in the DOM. If consumers remove options from the DOM based on the "filter" event, then the corresponding tags for those options will also be removed.

Making matter worse is that Dropdown also does its own filtering, which happens synchronously and doesn't take into account consumers wanting to filter a different way or on the server.

One solution, here, to both problems is to provide a filter() method that consumers can override. It's not very web component-y. But it seems to be the only path forward—though I'm totally open to alternatives. filter() returns a promise that Dropdown awaits before showing and hiding options.

📋 Checklist

🔬 How to Test

  1. Navigate to filterable Dropdown in Storybook.
  2. Enter some text into the <input>.
  3. Verify filtering works as it does in production.

📸 Images/Videos of Functionality

N/A

Copy link

changeset-bot bot commented Nov 8, 2024

🦋 Changeset detected

Latest commit: 1c20438

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

This PR includes changesets to release 1 package
Name Type
@crowdstrike/glide-core Minor

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

Copy link
Contributor

github-actions bot commented Nov 8, 2024

@clintcs clintcs force-pushed the rework-dropdown-filtering branch 2 times, most recently from 69cf44d to 05b58e5 Compare November 8, 2024 16:59
}\n\n// When overriding, return the options you want visible. The rest will be hidden. If you fetch on\n// filter, this is the place to do it.`,
},
},
},
Copy link
Collaborator Author

@clintcs clintcs Nov 8, 2024

Choose a reason for hiding this comment

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

image

@clintcs clintcs force-pushed the rework-dropdown-filtering branch 3 times, most recently from 9b3c34a to eeb5019 Compare November 8, 2024 17:09
// eslint-disable-next-line no-empty
} catch {}

if (options) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Wrapped everything below in this condition. No other changes.

@clintcs clintcs force-pushed the rework-dropdown-filtering branch from eeb5019 to 1c20438 Compare November 8, 2024 17:12
@clintcs clintcs marked this pull request as ready for review November 8, 2024 17:13
Copy link
Collaborator

@ynotdraw ynotdraw left a comment

Choose a reason for hiding this comment

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

Really happy with this approach. Thanks!

@clintcs
Copy link
Collaborator Author

clintcs commented Nov 8, 2024

Really happy with this approach. Thanks!

Same, yeah.

filter() is an indirection. It's just an awkward middleman given consumers can set hidden on options themselves. But I think filter() is the best approach because of what you brought up—that dispatching a "filter" event and having consumers set hidden would mean that every consumer has to do so because Dropdown is automatically filterable when it has 10 or more options.

});
}

// eslint-disable-next-line @typescript-eslint/require-await
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Rather than needing to eslint-disable, maybe you could have the function return an immediately-resolving Promise? I realize it's effectively the same behavior, but maybe it's slightly more readable? (and I'm eslint-disable-phobic)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Haha. It wouldn't be self documenting, would it? I could see someone coming along and wondering why we're doing it, removing await Promise.resolve(...), then discovering the lint error.

Copy link
Collaborator Author

@clintcs clintcs Nov 8, 2024

Choose a reason for hiding this comment

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

@danwenzel: I've got some other work that this depends on. So I'm going to merge. Feel free to chime in after I merge.

@clintcs clintcs merged commit 7017a73 into main Nov 8, 2024
7 checks passed
@clintcs clintcs deleted the rework-dropdown-filtering branch November 8, 2024 20:35
@github-actions github-actions bot mentioned this pull request Nov 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载