question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[theme] `theme.transition.create` defaults to non theme easing value

See original GitHub issue

If you try to modify the theme.transition.easing object in the theme, it does not seem to apply to the components.

Here’s a reproduction: https://codesandbox.io/s/youthful-noether-rex8r?file=/src/App.js

If you inspect the <ListItem button />, you’ll see that it has a transition with a cubic-bezier that does not match with the theme I provide, even though the transition duration is updated properly.

Version: v4.11.3

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
pandeymanggcommented, Apr 29, 2021

Hey, can I work on this?

1reaction
mnajdovacommented, Apr 28, 2021

That’s a good point. We can create createTransitions factory. It could look something like this:

import { easing, duration, getAutoHeightDuration } from './transitions';

function formatMs(milliseconds) {
  return `${Math.round(milliseconds)}ms`;
}

export default function createTransitions(inputTransitions) {
  const mergedEasing = {
    ...easing,
    ...inputTransitions.easing,
  };

  const mergedDuration = {
    ...duration,
    ...inputTransitions.duration,
  };

  const create = (props = ['all'], options = {}) => {
    const {
      duration: durationOption = mergedDuration.standard,
      easing: easingOption = mergedEasing.easeInOut,
      delay = 0,
      ...other
    } = options;
  
    if (process.env.NODE_ENV !== 'production') {
      const isString = (value) => typeof value === 'string';
      // IE11 support, replace with Number.isNaN
      // eslint-disable-next-line no-restricted-globals
      const isNumber = (value) => !isNaN(parseFloat(value));
      if (!isString(props) && !Array.isArray(props)) {
        console.error('Material-UI: Argument "props" must be a string or Array.');
      }
  
      if (!isNumber(durationOption) && !isString(durationOption)) {
        console.error(
          `Material-UI: Argument "duration" must be a number or a string but found ${durationOption}.`,
        );
      }
  
      if (!isString(easingOption)) {
        console.error('Material-UI: Argument "easing" must be a string.');
      }
  
      if (!isNumber(delay) && !isString(delay)) {
        console.error('Material-UI: Argument "delay" must be a number or a string.');
      }
  
      if (Object.keys(other).length !== 0) {
        console.error(`Material-UI: Unrecognized argument(s) [${Object.keys(other).join(',')}].`);
      }
    }
  
    return (Array.isArray(props) ? props : [props])
      .map(
        (animatedProp) =>
          `${animatedProp} ${
            typeof durationOption === 'string' ? durationOption : formatMs(durationOption)
          } ${easingOption} ${typeof delay === 'string' ? delay : formatMs(delay)}`,
      )
      .join(',');
  }

  return {
    easing: mergedEasing,
    duration: mergedDuration,
    getAutoHeightDuration,
    create,
  };
}

I’ve copied the create function from transitions.js and changed the default duration and easing to be from the merged values. We can remove the create function defined in transition.js after this change.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Transitions - Material UI - MUI
The theme key enables you to customize the durations and easings of the various transitions used across MUI components, and offers a utility...
Read more >
[Transitions] Some components don't use transition durations ...
I noticed this when trying to tweak the transitions for a test environment to set them all to 0 / "none" to make...
Read more >
transition-timing-function - CSS: Cascading Style Sheets | MDN
The transition-timing-function CSS property sets how intermediate values are calculated for CSS properties being affected by a transition ...
Read more >
MUI: Overriding easing/timing function in Slide Transition ...
In MUI v5, you can change the default timing functions of the Slide component by overriding the easing props:
Read more >
Transition Property - Tailwind CSS
If you need to use a one-off transition-property value that doesn't make sense to include in your theme, use square brackets to generate...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found