Skip to content

Commit

Permalink
Fix sidebar reduce motion in customizer
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 committed Mar 22, 2022
1 parent 434c439 commit c73acec
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions packages/customize-widgets/src/controls/sidebar-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ export default function getSidebarSection() {
wp: { customize },
} = window;

const reduceMotionMediaQuery = window.matchMedia(
'(prefers-reduced-motion: reduce)'
);
let isReducedMotion = reduceMotionMediaQuery.matches;
reduceMotionMediaQuery.addEventListener( 'change', ( event ) => {
isReducedMotion = event.matches;
} );

return class SidebarSection extends customize.Section {
ready() {
const InspectorSection = getInspectorSection();
Expand Down Expand Up @@ -58,10 +66,6 @@ export default function getSidebarSection() {
this.contentContainer
.closest( '.wp-full-overlay' )
.addClass( 'section-open' );
this.contentContainer.one( 'transitionend', () => {
this.contentContainer.removeClass( 'busy' );
args.completeCallback();
} );
} else {
this.contentContainer.addClass( [
'busy',
Expand All @@ -71,10 +75,20 @@ export default function getSidebarSection() {
.closest( '.wp-full-overlay' )
.addClass( 'section-open' );
this.contentContainer.removeClass( 'open' );
this.contentContainer.one( 'transitionend', () => {
this.contentContainer.removeClass( 'busy' );
args.completeCallback();
} );
}

const handleTransitionEnd = () => {
this.contentContainer.removeClass( 'busy' );
args.completeCallback();
};

if ( isReducedMotion ) {
handleTransitionEnd();
} else {
this.contentContainer.one(
'transitionend',
handleTransitionEnd
);
}
} else {
super.onChangeExpanded( expanded, args );
Expand Down

0 comments on commit c73acec

Please sign in to comment.