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

[TreeView] Add utility function to check if an optional plugin is present #13788

Merged
merged 3 commits into from
Jul 11, 2024

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Jul 10, 2024

Closes #13777

@flaviendelangle flaviendelangle added the component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! label Jul 10, 2024
@flaviendelangle flaviendelangle self-assigned this Jul 10, 2024
@@ -0,0 +1,12 @@
import { TreeViewAnyPluginSignature, TreeViewInstance, TreeViewPlugin } from '../models';

export const hasPlugin = <
Copy link
Member Author

Choose a reason for hiding this comment

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

I can't have this inside useTreeViewOptionalPlugins because instance needs to be a param in order to infer its shape.

Otherwise we would need to do instance.hasPlugin(instance, plugin) which is worse IMHO.

@@ -142,7 +143,9 @@ export const useTreeViewKeyboardNavigation: TreeViewPlugin<
const nextItem = getNextNavigableItem(instance, itemId);
if (nextItem) {
event.preventDefault();
instance.focusItem(event, nextItem);
if (hasPlugin(instance, useTreeViewFocus)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I used this plugin as an example but I will remove before merging 👌

@mui-bot
Copy link

mui-bot commented Jul 10, 2024

Deploy preview: https://deploy-preview-13788--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against 85fa798

Copy link
Contributor

@noraleonte noraleonte left a comment

Choose a reason for hiding this comment

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

That was so fast⚡
LGTM 🐈‍⬛

@flaviendelangle flaviendelangle merged commit d3fad51 into mui:master Jul 11, 2024
17 checks passed
@flaviendelangle flaviendelangle deleted the hasPlugin-utils branch July 11, 2024 08:44
DungTiger pushed a commit to DungTiger/mui-x that referenced this pull request Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TreeView] Add method to check the existence of optional dependencies
3 participants