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

Fixed lagging state of multiselect FluentUI component and added searchable options to select and multiselect #1090

Merged
merged 10 commits into from
Jul 24, 2024

Conversation

TimWillebrands
Copy link
Contributor

I ran into an issue where when I used the fluent-ui multiselect the state of the selection would lag behind the selection in the component itself. This happened because there where two react state setters where the second setter depended on the value set by the first:

setSelectedKeys(
    item.selected
      ? [...selectedKeys, item.key]
      : selectedKeys.filter((key) => key !== item.key)
);
setValue(selectedKeys);

My fix was to determine the selection separate from the setters and pass that to both setters in one go:

const newSelectedItems = item.selected
  ? [...selectedKeys, item.key]
  : selectedKeys.filter((key) => key !== item.key);

setSelectedKeys(newSelectedItems);
setValue(newSelectedItems);

Then I also lacked search in the fluent-ui select & multiselect widgets, I contemplated adding it by switching to fluent's ComboBox component since it seemed a bit more in-line with how fluent prescribes the usecase. But that way it didn't really match the way the other ui-framework widgets do search, which is admittedly a bit nicer than the combobox.
Ultimately I made a 'SearchableDropdown' component based on a reply on this Fluent-UI issue and used that instead.

Copy link

codesandbox bot commented Jul 12, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

vercel bot commented Jul 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-awesome-query-builder-examples ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 12, 2024 4:17pm
react-awesome-query-builder-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 12, 2024 4:17pm
react-awesome-query-builder-sandbox-next ✅ Ready (Inspect) Visit Preview Jul 12, 2024 4:17pm

Copy link

codesandbox-ci bot commented Jul 12, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 09a6f3f:

Sandbox Source
@react-awesome-query-builder/examples Configuration
@react-awesome-query-builder/sandbox Configuration
@react-awesome-query-builder/sandbox-simple Configuration
@react-awesome-query-builder/sandbox-next Configuration

Copy link

codecov bot commented Jul 12, 2024

Codecov Report

Attention: Patch coverage is 14.28571% with 12 lines in your changes missing coverage. Please review.

Project coverage is 82.10%. Comparing base (cf87d44) to head (09a6f3f).
Report is 1 commits behind head on master.

Files Patch % Lines
...ages/fluent/modules/widgets/SearchableDropdown.jsx 14.28% 6 Missing ⚠️
...uent/modules/widgets/value/FluentUIMultiSelect.jsx 16.66% 4 Missing and 1 partial ⚠️
...es/fluent/modules/widgets/value/FluentUISelect.jsx 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1090      +/-   ##
==========================================
- Coverage   82.15%   82.10%   -0.06%     
==========================================
  Files         211      212       +1     
  Lines       11099    11107       +8     
  Branches     1332     1335       +3     
==========================================
+ Hits         9118     9119       +1     
- Misses       1367     1373       +6     
- Partials      614      615       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vercel vercel bot temporarily deployed to Preview – react-awesome-query-builder-sandbox-next July 12, 2024 13:08 Inactive
@vercel vercel bot temporarily deployed to Preview – react-awesome-query-builder-sandbox July 12, 2024 13:09 Inactive
@ukrbublik
Copy link
Owner

ukrbublik commented Jul 12, 2024

Thanks for the PR.

Search in select boxes looks cool.

However I see one issue with the line you've deleted

selectedKeys={selectedKeys}

Multiselect ignores value prop

@ukrbublik
Copy link
Owner

Btw, I think that using ComboBox with allowFreeform is a good idea in order to support allowCustomValues


https://github.com/ukrbublik/react-awesome-query-builder/blob/master/packages/examples/demo/config.tsx#L572

Copy link
Owner

@ukrbublik ukrbublik left a comment

Choose a reason for hiding this comment

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

Please remove selectedKeys state from FluentUIMultiSelect component and pass selectedKeys prop to Dropdown

@TimWillebrands
Copy link
Contributor Author

I think my last commit should deal with the useless state, and passed the value directly to the dropdown

@ukrbublik ukrbublik self-requested a review July 12, 2024 15:04
@TimWillebrands
Copy link
Contributor Author

Forgot to run the linter....

@ukrbublik ukrbublik merged commit 39da010 into ukrbublik:master Jul 24, 2024
11 of 13 checks passed
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.

2 participants