@@ -284,11 +284,6 @@ var component = function component(_ref) {
284284 var $elWrapper = $wrapper ;
285285 var $elItemsWrapper = $itemsWrapper ;
286286 var $itemsRef = [ ] ;
287-
288- for ( var i = 0 ; i < optionList . length ; i += 1 ) {
289- $itemsRef . push ( useRef ( null ) ) ;
290- }
291-
292287 var handleOnBlur = useCallback ( function ( e ) {
293288 if ( onBlur ) {
294289 check ( ) ;
@@ -397,53 +392,51 @@ var component = function component(_ref) {
397392 var scroll = useCallback ( function ( ) {
398393 var direction = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : undefined ;
399394
400- if ( $elItemsWrapper === null ) {
401- return ;
402- }
403-
404- var containerHeight = $elItemsWrapper . current . offsetHeight ;
405- var containerScrollTop = $elItemsWrapper . current . scrollTop ;
395+ if ( $itemsWrapper && $itemsWrapper . current && $itemsWrapper . current . children ) {
396+ var $children = $itemsWrapper . current . children ;
406397
407- if ( ! globalVariableCurrentFocus || ! $itemsRef [ globalVariableCurrentFocus ] ) {
408- return ;
409- }
398+ if ( $elItemsWrapper === null ) {
399+ return ;
400+ }
410401
411- var $elOptionItem = $itemsRef [ globalVariableCurrentFocus ] ;
402+ var containerHeight = $elItemsWrapper . current . offsetHeight ;
403+ var containerScrollTop = $elItemsWrapper . current . scrollTop ;
412404
413- if ( $elOptionItem === null ) {
414- return ;
415- }
405+ if ( ! globalVariableCurrentFocus || ! $children [ globalVariableCurrentFocus ] ) {
406+ return ;
407+ }
416408
417- var itemHeight = $elOptionItem . current . offsetHeight ;
409+ var itemHeight = $children [ globalVariableCurrentFocus ] . offsetHeight ;
418410
419- if ( direction ) {
420- if ( direction === 'down' ) {
421- var bound = containerScrollTop + containerHeight ;
422- var heightItems = globalVariableCurrentFocus * itemHeight ;
423- var heightContainer = bound - itemHeight ;
411+ if ( direction ) {
412+ if ( direction === 'down' ) {
413+ var bound = containerScrollTop + containerHeight ;
414+ var heightItems = globalVariableCurrentFocus * itemHeight ;
415+ var heightContainer = bound - itemHeight ;
424416
425- if ( heightItems >= heightContainer ) {
426- var offset = Math . abs ( heightItems - heightContainer - itemHeight ) ;
417+ if ( heightItems >= heightContainer ) {
418+ var offset = Math . abs ( heightItems - heightContainer - itemHeight ) ;
427419
428- if ( offset >= 0 && ! globalVariableIsCorrected ) {
429- $elItemsWrapper . current . scrollTop = containerScrollTop + itemHeight - offset ;
430- globalVariableIsCorrected = true ;
431- } else {
432- $elItemsWrapper . current . scrollTop = containerScrollTop + itemHeight ;
420+ if ( offset >= 0 && ! globalVariableIsCorrected ) {
421+ $elItemsWrapper . current . scrollTop = containerScrollTop + itemHeight - offset ;
422+ globalVariableIsCorrected = true ;
423+ } else {
424+ $elItemsWrapper . current . scrollTop = containerScrollTop + itemHeight ;
425+ }
433426 }
434427 }
435- }
436428
437- if ( direction === 'up' ) {
438- globalVariableIsCorrected = false ;
429+ if ( direction === 'up' ) {
430+ globalVariableIsCorrected = false ;
439431
440- if ( globalVariableCurrentFocus * itemHeight <= containerScrollTop ) {
441- $elItemsWrapper . current . scrollTop = globalVariableCurrentFocus * itemHeight ;
432+ if ( globalVariableCurrentFocus * itemHeight <= containerScrollTop ) {
433+ $elItemsWrapper . current . scrollTop = globalVariableCurrentFocus * itemHeight ;
434+ }
442435 }
436+ } else {
437+ globalVariableIsCorrected = false ;
438+ $elItemsWrapper . current . scrollTop = globalVariableCurrentFocus * itemHeight ;
443439 }
444- } else {
445- globalVariableIsCorrected = false ;
446- $elItemsWrapper . current . scrollTop = globalVariableCurrentFocus * itemHeight ;
447440 }
448441 } , [ ] ) ;
449442 var handleOnItemClick = useCallback ( function ( v , e ) {
@@ -460,29 +453,21 @@ var component = function component(_ref) {
460453 removeActive ( ) ;
461454 } , [ ] ) ;
462455 var addActive = useCallback ( function ( ) {
463- if ( ! $itemsRef ) return ;
464- removeActive ( ) ;
465- if ( globalVariableCurrentFocus === null ) return ;
466- if ( globalVariableCurrentFocus >= $itemsRef . length ) globalVariableCurrentFocus = 0 ;
467- if ( globalVariableCurrentFocus < 0 ) globalVariableCurrentFocus = $itemsRef . length - 1 ;
468- var $node = $itemsRef [ globalVariableCurrentFocus ] ;
469-
470- if ( ! $node ) {
471- return ;
456+ if ( $itemsWrapper && $itemsWrapper . current && $itemsWrapper . current . children ) {
457+ var $children = $itemsWrapper . current . children ;
458+ removeActive ( ) ;
459+ if ( globalVariableCurrentFocus === null ) return ;
460+ if ( globalVariableCurrentFocus >= $children . length ) globalVariableCurrentFocus = 0 ;
461+ if ( globalVariableCurrentFocus < 0 ) globalVariableCurrentFocus = $children . length - 1 ;
462+ $children [ globalVariableCurrentFocus ] . className += " " . concat ( reactInputsValidationCss [ "" . concat ( TYPE , "__hover-active" ) ] ) ;
472463 }
473-
474- $itemsRef [ globalVariableCurrentFocus ] . current . className += " " . concat ( reactInputsValidationCss [ "" . concat ( TYPE , "__hover-active" ) ] ) ;
475464 } , [ ] ) ;
476465 var removeActive = useCallback ( function ( ) {
477- for ( var _i2 = 0 ; _i2 < $itemsRef . length ; _i2 += 1 ) {
478- var $node = $itemsRef [ _i2 ] ;
479-
480- if ( ! $node ) {
481- break ;
482- }
466+ if ( $itemsWrapper && $itemsWrapper . current && $itemsWrapper . current . children ) {
467+ var $children = $itemsWrapper . current . children ;
483468
484- if ( $node && $node . current ) {
485- $node . current . className = $node . current . className . replace ( reactInputsValidationCss [ "" . concat ( TYPE , "__hover-active" ) ] , '' ) ;
469+ for ( var i = 0 ; i < $children . length ; i += 1 ) {
470+ $children [ i ] . className = $children [ i ] . className . replace ( reactInputsValidationCss [ "" . concat ( TYPE , "__hover-active" ) ] , '' ) ;
486471 }
487472 }
488473 } , [ ] ) ;
@@ -533,10 +518,14 @@ var component = function component(_ref) {
533518 addActive ( ) ;
534519 } else if ( keyCode === keyCodeEnter ) {
535520 if ( globalVariableCurrentFocus > - 1 ) {
536- if ( $itemsRef [ globalVariableCurrentFocus ] ) {
537- $itemsRef [ globalVariableCurrentFocus ] . current . click ( ) ;
538- } else {
539- return ;
521+ if ( $itemsWrapper && $itemsWrapper . current && $itemsWrapper . current . children ) {
522+ var $children = $itemsWrapper . current . children ;
523+
524+ if ( $children [ globalVariableCurrentFocus ] ) {
525+ $children [ globalVariableCurrentFocus ] . click ( ) ;
526+ } else {
527+ return ;
528+ }
540529 }
541530 }
542531 }
@@ -611,7 +600,7 @@ var component = function component(_ref) {
611600 useEffect ( function ( ) {
612601 if ( show ) {
613602 globalVariableCurrentFocus = globalVariableCurrentFocus === null ? getIndex ( optionList , String ( value ) ) : globalVariableCurrentFocus ;
614- $itemsRef [ globalVariableCurrentFocus ] . current . focus ( ) ;
603+ $itemsRef [ globalVariableCurrentFocus ] && $itemsRef [ globalVariableCurrentFocus ] . current . focus ( ) ;
615604 } else {
616605 $elButton . current . focus ( ) ;
617606 }
@@ -649,7 +638,6 @@ var component = function component(_ref) {
649638 key : k ,
650639 index : k ,
651640 id : "react-inputs-validation__select_option-" . concat ( i . id ) ,
652- refItem : $itemsRef [ k ] ,
653641 className : String ( i . id ) === String ( value ) ? "" . concat ( selectOptionListItemClass , " " ) . concat ( reactInputsValidationCss [ 'active' ] ) : "" . concat ( selectOptionListItemClass ) ,
654642 item : i ,
655643 customStyleOptionListItem : customStyleOptionListItem ,
@@ -703,8 +691,6 @@ var component = function component(_ref) {
703691var Option = memo ( function ( _ref2 ) {
704692 var _ref2$index = _ref2 . index ,
705693 index = _ref2$index === void 0 ? - 1 : _ref2$index ,
706- _ref2$refItem = _ref2 . refItem ,
707- refItem = _ref2$refItem === void 0 ? null : _ref2$refItem ,
708694 _ref2$id = _ref2 . id ,
709695 id = _ref2$id === void 0 ? '' : _ref2$id ,
710696 _ref2$className = _ref2 . className ,
@@ -738,7 +724,6 @@ var Option = memo(function (_ref2) {
738724 } , [ ] ) ;
739725 return React . createElement ( "a" , {
740726 id : id ,
741- ref : refItem ,
742727 onMouseOver : handleOnMouseOver ,
743728 onMouseMove : handleOnMouseMove ,
744729 onMouseOut : handleOnMouseOut ,
0 commit comments