Skip to content

Commit

Permalink
fix(TreeList): rename prop
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaevAlexandr committed Jun 20, 2024
1 parent 1b0b182 commit 6009d1e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/components/TreeList/TreeList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const TreeList = <T,>({
renderItem: propsRenderItem,
renderContainer = ListContainer,
onItemClick: propsOnItemClick,
disableDefaultClickHandler,
disableDefaultItemClickBehavior,
mapItemDataToProps,
}: TreeListProps<T>) => {
const uniqId = useUniqId();
Expand All @@ -37,14 +37,14 @@ export const TreeList = <T,>({
const containerRef = propsContainerRef ?? containerRefLocal;

const onItemClick = React.useMemo(() => {
if (disableDefaultClickHandler && !propsOnItemClick) {
if (disableDefaultItemClickBehavior && !propsOnItemClick) {
return undefined;
}

const handler: ListOnItemClick = (arg, e) => {
const payload = {id: arg.id, list};

if (!disableDefaultClickHandler) {
if (!disableDefaultItemClickBehavior) {
const baseOnClick = getListItemClickHandler({list, multiple});

baseOnClick(payload, e);
Expand All @@ -54,7 +54,7 @@ export const TreeList = <T,>({
};

return handler;
}, [disableDefaultClickHandler, propsOnItemClick, list, multiple]);
}, [disableDefaultItemClickBehavior, propsOnItemClick, list, multiple]);

useListKeydown({
containerRef,
Expand Down
26 changes: 13 additions & 13 deletions src/components/TreeList/__stories__/TreeListDocs.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ const Component = () => {

## Props:

| Name | Description | Type | Default |
| :------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------: | :-----: |
| list | result of [list](/docs/lab-uselist--docs#uselist) hook. | `UseList` | |
| containerRef | a reference to the DOM element of the List container inside which to search for its elements; | `React.RefObject<HTMLDivElement \| HTMLUlElement>` | |
| qa | Selector for tests | `string` | |
| size | The size of the element. This also affects the rounding radius of the list element | `s \| m \| l \| xl` | `m` |
| mapItemDataToProps | Map list item data (`T`) to `ListItemView` props | `(data: T) => ListItemCommonProps` | |
| multiple | One or multiple elements selected list | `boolean` | `false` |
| id | id attribute | `string` | |
| renderItem | Redefine the rendering of a list item. For example, add dividers between list items or wrap an item in a link component. As a view component to display a list item, use [ListItemView](/docs/lab-uselist--docs#listitemview); | `(props: TreeListRenderItem<T, P>) => React.JSX.Element` | |
| renderContainer | Render custom list container. | `(props: TreeListRenderContainer<T>) => React.JSX.Element` | |
| onItemClick | Override default on click behavior. Pass `null` to disable on click handler | `(props: {id: ListItemId; list: UseList<T>}, e: React.SyntheticEvent) => void \| null` | |
| disableDefaultClickHandler | Disable default `onItemClick` handler logic | `TreeListOnItemClick<T> \| null` | |
| Name | Description | Type | Default |
| :------------------------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------: | :-----: |
| list | result of [list](/docs/lab-uselist--docs#uselist) hook. | `UseList` | |
| containerRef | a reference to the DOM element of the List container inside which to search for its elements; | `React.RefObject<HTMLDivElement \| HTMLUlElement>` | |
| qa | Selector for tests | `string` | |
| size | The size of the element. This also affects the rounding radius of the list element | `s \| m \| l \| xl` | `m` |
| mapItemDataToProps | Map list item data (`T`) to `ListItemView` props | `(data: T) => ListItemCommonProps` | |
| multiple | One or multiple elements selected list | `boolean` | `false` |
| id | id attribute | `string` | |
| renderItem | Redefine the rendering of a list item. For example, add dividers between list items or wrap an item in a link component. As a view component to display a list item, use [ListItemView](/docs/lab-uselist--docs#listitemview); | `(props: TreeListRenderItem<T, P>) => React.JSX.Element` | |
| renderContainer | Render custom list container. | `(props: TreeListRenderContainer<T>) => React.JSX.Element` | |
| onItemClick | Override default on click behavior. Pass `null` to disable on click handler | `(props: {id: ListItemId; list: UseList<T>}, e: React.SyntheticEvent) => void \| null` | |
| disableDefaultItemClickBehavior | Disable default `onItemClick` handler logic | `TreeListOnItemClick<T> \| null` | |

### TreeListRenderItem props:

Expand Down
4 changes: 2 additions & 2 deletions src/components/TreeList/__stories__/stories/DefaultStory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const DefaultStory = ({itemsCount = 5, ...props}: DefaultStoryProps) => {
list={listWithGroups}
onItemClick={null}
mapItemDataToProps={identity}
disableDefaultClickHandler
disableDefaultItemClickBehavior
/>
</Flex>
<Flex direction={'column'} gap="3">
Expand All @@ -48,7 +48,7 @@ export const DefaultStory = ({itemsCount = 5, ...props}: DefaultStoryProps) => {
list={listWithNoGroups}
onItemClick={null}
mapItemDataToProps={identity}
disableDefaultClickHandler
disableDefaultItemClickBehavior
/>
</Flex>
</Flex>
Expand Down
2 changes: 1 addition & 1 deletion src/components/TreeList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ export interface TreeListProps<T, P extends {} = {}> extends QAProps {
/**
* Disable default `onItemClick` handler logic
*/
disableDefaultClickHandler?: boolean;
disableDefaultItemClickBehavior?: boolean;
mapItemDataToProps: TreeListMapItemDataToProps<T>;
}
8 changes: 4 additions & 4 deletions src/components/TreeSelect/TreeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const TreeSelect = React.forwardRef(function TreeSelect<T>(
defaultValue,
withExpandedState = true,
defaultExpandedState = 'expanded',
disableDefaultClickHandler,
disableDefaultItemClickBehavior,
onClose,
onOpenChange,
onUpdate,
Expand Down Expand Up @@ -103,7 +103,7 @@ export const TreeSelect = React.forwardRef(function TreeSelect<T>(
});

const handleItemClick = React.useMemo(() => {
if (disableDefaultClickHandler && !onItemClick) {
if (disableDefaultItemClickBehavior && !onItemClick) {
return undefined;
}

Expand All @@ -112,7 +112,7 @@ export const TreeSelect = React.forwardRef(function TreeSelect<T>(

if (list.state.disabledById[id]) return;

if (!disableDefaultClickHandler) {
if (!disableDefaultItemClickBehavior) {
// always activate selected item
list.state.setActiveItemId(id);

Expand All @@ -136,7 +136,7 @@ export const TreeSelect = React.forwardRef(function TreeSelect<T>(
return handler;
}, [
multiple,
disableDefaultClickHandler,
disableDefaultItemClickBehavior,
onItemClick,
handleMultipleSelection,
handleSingleSelection,
Expand Down

0 comments on commit 6009d1e

Please sign in to comment.