@@ -114,6 +114,10 @@ const didPropChange = (propList, prev, next) => {
114114 return hasPropsChanged . indexOf ( true ) !== - 1 ;
115115} ;
116116
117+ const getMarqueeOn = function ( props , context , marqueeOnDefault = 'focus' ) {
118+ return ( props . marqueeOn || ( context && context . marqueeOn ) || marqueeOnDefault ) ;
119+ } ;
120+
117121/*
118122 * There's only one timer shared for Marquee so we need to keep track of what we may be using it
119123 * for. We may need to clean up certain things as we move among states.
@@ -304,15 +308,13 @@ const MarqueeDecorator = hoc(defaultConfig, (config, Wrapped) => {
304308
305309 static defaultProps = {
306310 marqueeDelay : 1000 ,
307- marqueeOn : 'focus' ,
311+ // marqueeOn: 'focus',
308312 marqueeOnRenderDelay : 1000 ,
309313 marqueeResetDelay : 1000 ,
310314 marqueeSpacing : '50%' ,
311315 marqueeSpeed : 60
312316 }
313317
314- static contextType = MarqueeControllerContext
315-
316318 constructor ( props ) {
317319 super ( props ) ;
318320 this . state = {
@@ -338,7 +340,7 @@ const MarqueeDecorator = hoc(defaultConfig, (config, Wrapped) => {
338340 }
339341
340342 this . validateTextDirection ( ) ;
341- if ( this . props . marqueeOn === 'render' ) {
343+ if ( getMarqueeOn ( this . props , this . context ) === 'render' ) {
342344 this . startAnimation ( this . props . marqueeOnRenderDelay ) ;
343345 }
344346 on ( 'keydown' , this . handlePointerHide ) ;
@@ -352,7 +354,7 @@ const MarqueeDecorator = hoc(defaultConfig, (config, Wrapped) => {
352354 }
353355
354356 componentDidUpdate ( prevProps ) {
355- const { children, disabled, forceDirection, locale, marqueeOn, marqueeDisabled, marqueeSpacing, marqueeSpeed, rtl} = this . props ;
357+ const { children, disabled, forceDirection, locale, marqueeOn = getMarqueeOn ( this . props , this . context ) , marqueeDisabled, marqueeSpacing, marqueeSpeed, rtl} = this . props ;
356358
357359 let forceRestartMarquee = false ;
358360
@@ -371,7 +373,8 @@ const MarqueeDecorator = hoc(defaultConfig, (config, Wrapped) => {
371373 this . invalidateMetrics ( ) ;
372374 this . cancelAnimation ( ) ;
373375 } else if (
374- prevProps . marqueeOn !== marqueeOn ||
376+ // prevProps.marqueeOn !== marqueeOn ||
377+ getMarqueeOn ( prevProps , this . context ) !== marqueeOn ||
375378 prevProps . marqueeDisabled !== marqueeDisabled ||
376379 prevProps . marqueeSpeed !== marqueeSpeed ||
377380 prevProps . forceDirection !== forceDirection
@@ -383,7 +386,7 @@ const MarqueeDecorator = hoc(defaultConfig, (config, Wrapped) => {
383386
384387 this . validateTextDirection ( ) ;
385388 if ( forceRestartMarquee || this . shouldStartMarquee ( ) ) {
386- this . tryStartingAnimation ( this . props . marqueeOn === 'render' ? this . props . marqueeOnRenderDelay : this . props . marqueeDelay ) ;
389+ this . tryStartingAnimation ( marqueeOn === 'render' ? this . props . marqueeOnRenderDelay : this . props . marqueeDelay ) ;
387390 }
388391 }
389392
@@ -402,6 +405,8 @@ const MarqueeDecorator = hoc(defaultConfig, (config, Wrapped) => {
402405 off ( 'keydown' , this . handlePointerHide ) ;
403406 }
404407
408+ static contextType = MarqueeControllerContext
409+
405410 promoteJob = new Job ( ( ) => {
406411 if ( ! this . contentFits ) {
407412 this . setState ( state => state . promoted ? null : { promoted : true } ) ;
@@ -462,7 +467,7 @@ const MarqueeDecorator = hoc(defaultConfig, (config, Wrapped) => {
462467 * @returns {Boolean } - `true` if a possible marquee condition exists
463468 */
464469 shouldStartMarquee ( ) {
465- const { disabled, marqueeDisabled, marqueeOn} = this . props ;
470+ const { disabled, marqueeDisabled, marqueeOn = getMarqueeOn ( this . props , this . context ) } = this . props ;
466471 return ! marqueeDisabled && (
467472 marqueeOn === 'render' ||
468473 ! this . sync && (
@@ -769,15 +774,15 @@ const MarqueeDecorator = hoc(defaultConfig, (config, Wrapped) => {
769774 forwardBlur ( ev , this . props ) ;
770775 if ( this . isFocused ) {
771776 this . isFocused = false ;
772- if ( ! this . sync && ! ( this . isHovered && this . props . marqueeOn === 'hover' ) ) {
777+ if ( ! this . sync && ! ( this . isHovered && getMarqueeOn ( this . props , this . context ) === 'hover' ) ) {
773778 this . cancelAnimation ( ) ;
774779 }
775780 }
776781 }
777782
778783 handleEnter = ( ev ) => {
779784 this . isHovered = true ;
780- if ( this . props . marqueeOn === 'hover' ) {
785+ if ( getMarqueeOn ( this . props , this . context ) === 'hover' ) {
781786 if ( this . sync ) {
782787 this . context . enter ( this ) ;
783788 } else if ( ! this . state . animating ) {
@@ -801,7 +806,7 @@ const MarqueeDecorator = hoc(defaultConfig, (config, Wrapped) => {
801806
802807 handleUnhover ( ) {
803808 this . isHovered = false ;
804- if ( this . props . marqueeOn === 'hover' ) {
809+ if ( getMarqueeOn ( this . props , this . context ) === 'hover' ) {
805810 if ( this . sync ) {
806811 this . context . leave ( this ) ;
807812 } else {
@@ -826,11 +831,13 @@ const MarqueeDecorator = hoc(defaultConfig, (config, Wrapped) => {
826831 alignment,
827832 children,
828833 disabled,
829- marqueeOn,
834+ marqueeOn = getMarqueeOn ( this . props , this . context ) ,
830835 marqueeSpeed,
831836 ...rest
832837 } = this . props ;
833838
839+ console . log ( 'marqueeOn:' , marqueeOn , this . context && this . context . marqueeOn , children ) ;
840+
834841 const marqueeOnFocus = marqueeOn === 'focus' ;
835842 const marqueeOnHover = marqueeOn === 'hover' ;
836843 const marqueeOnRender = marqueeOn === 'render' ;
0 commit comments