Can't clear the last and second last selected values from a multiselect if a scroll bar is implemented

I implemented a scroll bar to a multiselect component in an application. The search function is also there in it. But when the scroll bar comes, I can't clear the last selected values. But the top values can. When trying to close by clicking the 'X' button, it's just getting flickering and the cursor will enter the search field.
Is there any solution to this?