Autocomplete listNoDataRender link

1 Answer 193 Views
AutoComplete DropDownList
Wreeecks
Top achievements
Rank 2
Iron
Iron
Iron
Wreeecks asked on 02 Feb 2022, 01:09 AM | edited on 02 Feb 2022, 05:31 AM

I'm creating a  custom listNoDataRender for autocomplete.

I wanted to add link that either redirects or updates the state, see my code below.

Unfortunately, clicking the button doesn't trigger the  onClick handler, it only closes the suggestion list.

How do i trigger the onClick handler and not close the suggestion list? TIA!

 

import * as React from 'react';
import * as ReactDOM from 'react-dom';

import { DropDownList } from '@progress/kendo-react-dropdowns';

const App = () => {

const handleClick = () =>{
 // update state or redirect here... 
}

 const listNoDataRender = (element: React.ReactElement<HTMLDivElement>) => {
      const noData = (
        <h4 style={{ fontSize: '1em' }}>
 <span className="k-icon k-i-warning" style={{ fontSize: '2.5em' }} />
 <br /><br />
 <button onClick={handleClick}>Did you mean reco..</button>
 </h4>
 );

      return React.cloneElement(element, { ...element.props }, noData);
  }

  return (
    <DropDownList
      style={{ width: '300px' }}
      data={[]}
      listNoDataRender={listNoDataRender}
      />
 );
}

ReactDOM.render(
  <App />,
 document.querySelector('my-app')
);

1 Answer, 1 is accepted

Sort by
1
Accepted
Stefan
Telerik team
answered on 02 Feb 2022, 07:05 AM

Hello,

That can be resolved by preventing the default behaviors of the onClick and the onMouseDown events. We use these events to close the list by default:

https://stackblitz.com/edit/react-1zafec?file=app/main.jsx

Regards,
Stefan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Wreeecks
Top achievements
Rank 2
Iron
Iron
Iron
commented on 02 Feb 2022, 11:15 PM

thanks Stefan! it worked!
Tags
AutoComplete DropDownList
Asked by
Wreeecks
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Stefan
Telerik team
Share this question
or