added `selectedIndex` check