Use more robust "find next carousel item" logic

Fixes #13818 and adds a relevant additional test.
CC: @fat for review