File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -452,6 +452,14 @@ export default class DatePicker extends Component<
452452 }
453453 } ;
454454
455+ safeFocus = ( ) => {
456+ setTimeout ( ( ) => {
457+ if ( this . input && this . input . focus ) {
458+ this . input . focus ( { preventScroll : true } ) ;
459+ }
460+ } , 0 ) ;
461+ } ;
462+
455463 safeBlur = ( ) => {
456464 setTimeout ( ( ) => {
457465 if ( this . input && this . input . blur ) {
@@ -461,9 +469,7 @@ export default class DatePicker extends Component<
461469 } ;
462470
463471 setFocus = ( ) => {
464- if ( this . input && this . input . focus ) {
465- this . input . focus ( { preventScroll : true } ) ;
466- }
472+ this . safeFocus ( ) ;
467473 } ;
468474
469475 setBlur = ( ) => {
Original file line number Diff line number Diff line change @@ -1983,7 +1983,7 @@ describe("DatePicker", () => {
19831983 } ) ;
19841984 expect ( div . querySelector ( "input" ) ) . toBe ( document . activeElement ) ;
19851985 } ) ;
1986- it ( "should autoFocus the input when calling the setFocus method" , ( ) => {
1986+ it ( "should autoFocus the input when calling the setFocus method" , async ( ) => {
19871987 const div = document . createElement ( "div" ) ;
19881988 document . body . appendChild ( div ) ;
19891989 let instance : DatePicker | null = null ;
@@ -2001,7 +2001,9 @@ describe("DatePicker", () => {
20012001 act ( ( ) => {
20022002 instance ! . setFocus ( ) ;
20032003 } ) ;
2004- expect ( div . querySelector ( "input" ) ) . toBe ( document . activeElement ) ;
2004+ await waitFor ( ( ) => {
2005+ expect ( div . querySelector ( "input" ) ) . toBe ( document . activeElement ) ;
2006+ } ) ;
20052007 } ) ;
20062008 it ( "should clear preventFocus timeout id when component is unmounted" , ( ) => {
20072009 const div = document . createElement ( "div" ) ;
You can’t perform that action at this time.
0 commit comments