Skip to content

Commit

Permalink
feat(TreeSelect): add onEnter api (#2731)
Browse files Browse the repository at this point in the history
* feat(TreeSelect): add onEnter api

* chore: update demo
  • Loading branch information
uyarn committed Jan 25, 2024
1 parent a8cbff4 commit 3b4d4df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/tree-select/TreeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const TreeSelect = forwardRef((props: TreeSelectProps, ref) => {
onFocus,
onSearch,
onRemove,
onEnter,
} = props;

const selectInputProps = useTreeSelectPassThroughProps(props);
Expand Down Expand Up @@ -249,6 +250,7 @@ const TreeSelect = forwardRef((props: TreeSelectProps, ref) => {

const handleEnter = usePersistFn<SelectInputProps['onEnter']>((_, ctx) => {
onSearch?.(ctx.inputValue, { e: ctx.e });
onEnter?.({ inputValue: ctx.inputValue, e: ctx.e, value: getTreeSelectEventValue() });
});

const handleFilterChange = usePersistFn<SelectInputProps['onInputChange']>((value, ctx) => {
Expand Down
6 changes: 5 additions & 1 deletion src/tree-select/_example/filterable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const options = [
export default function Example() {
const [type, setType] = useState('default');

function handleEnter(ctx) {
console.log('onEnter api:', ctx);
}

function filterFunction(searchText, node) {
return node.data.label.indexOf(searchText) >= 0;
}
Expand All @@ -47,7 +51,7 @@ export default function Example() {
</Radio.Group>
{type === 'default' ? (
<>
<TreeSelect data={options} clearable filterable placeholder="请选择" />
<TreeSelect data={options} clearable filterable placeholder="请选择" onEnter={handleEnter} />
<TreeSelect data={options} multiple clearable filterable placeholder="请选择" />
</>
) : (
Expand Down

0 comments on commit 3b4d4df

Please sign in to comment.