Skip to content

Commit

Permalink
* pick-pop: add onClickItem option.
Browse files Browse the repository at this point in the history
  • Loading branch information
YonLJ committed Nov 4, 2024
1 parent b7f002b commit af0185d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/pick/src/components/pick-pop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ export class PickPop<S extends PickState = PickState, P extends PickPopProps<S>
}

protected _handleClick(event: MouseEvent) {
const {togglePop} = this.props;
const {togglePop, onClickItem, state} = this.props;
const $target = $(event.target as HTMLElement);
const $value = $target.closest('[data-pick-value]');
if (onClickItem) {
onClickItem(event, state.value);
}

if ($value.length) {
event.stopPropagation();
return togglePop(false, {value: `${$value.dataset('pickValue')}`} as Partial<S>);
Expand Down
1 change: 1 addition & 0 deletions lib/pick/src/components/pick.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export class Pick<S extends PickState = PickState, O extends PickOptions<S> = Pi
maxWidth: props.popMaxWidth,
minWidth: props.popMinWidth,
limitInScreen: props.limitPopInScreen,
onClickItem: props.onClickItem,
};
}

Expand Down
1 change: 1 addition & 0 deletions lib/pick/src/types/pick-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ export interface PickOptions<S extends PickState = PickState> {
onPopShown?: () => void;
onPopHide?: () => void;
onPopHidden?: () => void;
onClickItem?: (event: MouseEvent, value: string) => void;
}
1 change: 1 addition & 0 deletions lib/pick/src/types/pick-pop-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface PickPopProps<S extends PickState = PickState> {
afterRender?: (info: {firstRender: boolean}) => void;
beforeDestroy?: () => void;
onLayout?: (element: HTMLElement) => void;
onClickItem?: (event: MouseEvent, state: string) => void;

limitInScreen?: boolean;
placement?: PickPopPlacement;
Expand Down

0 comments on commit af0185d

Please sign in to comment.