File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -55,9 +55,20 @@ export default class YearDropdownOptions extends React.Component {
5555
5656 componentDidMount ( ) {
5757 const dropdownCurrent = this . dropdownRef . current ;
58+
5859 if ( dropdownCurrent ) {
59- dropdownCurrent . scrollTop =
60- dropdownCurrent . scrollHeight / 2 - dropdownCurrent . clientHeight / 2 ;
60+ // Get array from HTMLCollection
61+ const dropdownCurrentChildren = dropdownCurrent . children
62+ ? Array . from ( dropdownCurrent . children )
63+ : null ;
64+ const selectedYearOptionEl = dropdownCurrentChildren
65+ ? dropdownCurrentChildren . find ( ( childEl ) => childEl . ariaSelected )
66+ : null ;
67+
68+ dropdownCurrent . scrollTop = selectedYearOptionEl
69+ ? selectedYearOptionEl . offsetTop +
70+ ( selectedYearOptionEl . clientHeight - dropdownCurrent . clientHeight ) / 2
71+ : ( dropdownCurrent . scrollHeight - dropdownCurrent . clientHeight ) / 2 ;
6172 }
6273 }
6374
You can’t perform that action at this time.
0 commit comments