Fix a bug in the updation of selectedItem.