This is a migrated thread and some comments may be shown as answers.

Multiselect prevent collapse after selecting item

2 Answers 529 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Lukáš
Top achievements
Rank 1
Lukáš asked on 16 Aug 2018, 08:19 AM

Hi,

I have a question about react multiselect component. How I can prevent collapse after I select item from multiselect. I saw in your api, it has onClose prop, which I should definitely use, but cant find anything, where I can .preventDefault() function.

https://www.telerik.com/kendo-react-ui/components/dropdowns/multiselect/

Thanks.

2 Answers, 1 is accepted

Sort by
0
Lukáš
Top achievements
Rank 1
answered on 16 Aug 2018, 10:25 AM

I solved this using onFocus and onBlur events

private onBlurEvent = (e: MultiSelectBlurEvent) => {
this.setState(prevState => ({
...prevState,
isOpened: false
}));
}

private onFocusEvent = (e: MultiSelectFocusEvent) => {
this.setState(prevState => ({
...prevState,
isOpened: true
}));
}

render() {
const value = this.state.multiSelectedData;
const selected = value.length;
return (
<MultiSelect
data={this.props.data}
onChange={this.checkGridItem}
value={this.state.multiSelectedData}
textField="localizedName"
dataItemKey="id"
itemRender={this.itemRender}
onFocus={this.onFocusEvent}
onBlur={this.onBlurEvent}
placeholder={this.props.placeholder}
opened={this.state.isOpened}
/>
);
}

0
Stefan
Telerik team
answered on 17 Aug 2018, 07:05 AM
Hello, Lukáš,

Thank you for sharing the approach with the community.

Indeed, in the native React version of the components, the approach is using the state variable for most of the modification and changes. If some action has to be prevented, the state either does not have to be changed and all will state the same, or in cases where we change it internally, the previous state value has to be set again.

As we encourage sharing different examples with the community I have added some Telerik points to your account for sharing this with us.

Regards,
Stefan
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Lukáš
Top achievements
Rank 1
Answers by
Lukáš
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or