Skip to content

Commit

Permalink
[TreeView] Improve the typing of the cancelable events (mui#13152)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle authored and thomasmoon committed Sep 6, 2024
1 parent 0ae1e2e commit 355b08a
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 6 deletions.
2 changes: 2 additions & 0 deletions docs/pages/x/api/tree-view/tree-item-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"disabled": { "type": { "name": "bool" }, "default": "false" },
"id": { "type": { "name": "string" } },
"label": { "type": { "name": "node" } },
"onBlur": { "type": { "name": "func" } },
"onFocus": { "type": { "name": "custom", "description": "unsupportedProp" } },
"onKeyDown": { "type": { "name": "func" } },
"slotProps": { "type": { "name": "object" }, "default": "{}" },
"slots": {
"type": { "name": "object" },
Expand Down
3 changes: 2 additions & 1 deletion docs/pages/x/api/tree-view/tree-item.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"disabled": { "type": { "name": "bool" }, "default": "false" },
"label": { "type": { "name": "node" } },
"onFocus": { "type": { "name": "custom", "description": "unsupportedProp" } },
"onKeyDown": { "type": { "name": "func" } },
"slotProps": { "type": { "name": "object" }, "default": "{}" },
"slots": {
"type": { "name": "object" },
Expand Down Expand Up @@ -41,7 +42,7 @@
},
{
"name": "groupTransition",
"description": "The component that animates to appearance / disappearance of the item's children.",
"description": "The component that animates the appearance / disappearance of the item's children.",
"default": "TreeItem2Group",
"class": "MuiTreeItem-groupTransition"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
"id": { "description": "The id attribute of the item. If not provided, it will be generated." },
"itemId": { "description": "The id of the item. Must be unique." },
"label": { "description": "The label of the item." },
"onBlur": { "description": "Callback fired when the item root is blurred." },
"onFocus": {
"description": "This prop isn&#39;t supported. Use the <code>onItemFocus</code> callback on the tree if you need to monitor a item&#39;s focus."
"description": "This prop isn&#39;t supported. Use the <code>onItemFocus</code> callback on the tree if you need to monitor an item&#39;s focus."
},
"onKeyDown": {
"description": "Callback fired when a key is pressed on the keyboard and the tree is in focus."
},
"slotProps": { "description": "The props used for each component slot." },
"slots": { "description": "Overridable component slots." }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"onFocus": {
"description": "This prop isn&#39;t supported. Use the <code>onItemFocus</code> callback on the tree if you need to monitor a item&#39;s focus."
},
"onKeyDown": {
"description": "Callback fired when a key of the keyboard is pressed on the item."
},
"slotProps": { "description": "The props used for each component slot." },
"slots": { "description": "Overridable component slots." },
"sx": {
Expand Down Expand Up @@ -60,7 +63,7 @@
"collapseIcon": "The icon used to collapse the item.",
"endIcon": "The icon displayed next to an end item.",
"expandIcon": "The icon used to expand the item.",
"groupTransition": "The component that animates to appearance / disappearance of the item&#39;s children.",
"groupTransition": "The component that animates the appearance / disappearance of the item&#39;s children.",
"icon": "The icon to display next to the tree item&#39;s label."
}
}
4 changes: 4 additions & 0 deletions packages/x-tree-view/src/TreeItem/TreeItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ TreeItem.propTypes = {
* Use the `onItemFocus` callback on the tree if you need to monitor a item's focus.
*/
onFocus: unsupportedProp,
/**
* Callback fired when a key of the keyboard is pressed on the item.
*/
onKeyDown: PropTypes.func,
/**
* The props used for each component slot.
* @default {}
Expand Down
7 changes: 6 additions & 1 deletion packages/x-tree-view/src/TreeItem/TreeItem.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { TreeItemContentProps } from './TreeItemContent';
import { TreeItemClasses } from './treeItemClasses';
import { TreeViewItemId } from '../models';
import { SlotComponentPropsFromProps } from '../internals/models';
import { MuiCancellableEventHandler } from '../internals/models/MuiCancellableEvent';

export interface TreeItemSlots {
/**
Expand All @@ -26,7 +27,7 @@ export interface TreeItemSlots {
*/
icon?: React.ElementType;
/**
* The component that animates to appearance / disappearance of the item's children.
* The component that animates the appearance / disappearance of the item's children.
* @default TreeItem2Group
*/
groupTransition?: React.ElementType;
Expand Down Expand Up @@ -91,6 +92,10 @@ export interface TreeItemProps extends Omit<React.HTMLAttributes<HTMLLIElement>,
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx?: SxProps<Theme>;
/**
* Callback fired when a key of the keyboard is pressed on the item.
*/
onKeyDown?: MuiCancellableEventHandler<React.KeyboardEvent<HTMLLIElement>>;
}

export interface TreeItemOwnerState extends TreeItemProps {
Expand Down
10 changes: 9 additions & 1 deletion packages/x-tree-view/src/TreeItem2/TreeItem2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,19 @@ TreeItem2.propTypes = {
* The label of the item.
*/
label: PropTypes.node,
/**
* Callback fired when the item root is blurred.
*/
onBlur: PropTypes.func,
/**
* This prop isn't supported.
* Use the `onItemFocus` callback on the tree if you need to monitor a item's focus.
* Use the `onItemFocus` callback on the tree if you need to monitor an item's focus.
*/
onFocus: unsupportedProp,
/**
* Callback fired when a key is pressed on the keyboard and the tree is in focus.
*/
onKeyDown: PropTypes.func,
/**
* The props used for each component slot.
* @default {}
Expand Down
11 changes: 10 additions & 1 deletion packages/x-tree-view/src/TreeItem2/TreeItem2.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SlotComponentProps } from '@mui/base/utils';
import { UseTreeItem2Parameters, UseTreeItem2Status } from '../useTreeItem2';
import { TreeItemClasses } from '../TreeItem';
import { TreeItem2IconSlotProps, TreeItem2IconSlots } from '../TreeItem2Icon';
import { MuiCancellableEventHandler } from '../internals/models/MuiCancellableEvent';

export interface TreeItem2Slots extends TreeItem2IconSlots {
/**
Expand Down Expand Up @@ -67,9 +68,17 @@ export interface TreeItem2Props
slotProps?: TreeItem2SlotProps;
/**
* This prop isn't supported.
* Use the `onItemFocus` callback on the tree if you need to monitor a item's focus.
* Use the `onItemFocus` callback on the tree if you need to monitor an item's focus.
*/
onFocus?: null;
/**
* Callback fired when the item root is blurred.
*/
onBlur?: MuiCancellableEventHandler<React.FocusEvent<HTMLLIElement>>;
/**
* Callback fired when a key is pressed on the keyboard and the tree is in focus.
*/
onKeyDown?: MuiCancellableEventHandler<React.KeyboardEvent<HTMLLIElement>>;
}

export interface TreeItem2OwnerState extends Omit<TreeItem2Props, 'disabled'>, UseTreeItem2Status {}

0 comments on commit 355b08a

Please sign in to comment.