Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui-toggle-details): fix ToggleDetails flickering #1651

Merged

Conversation

joyenjoyer
Copy link
Contributor

@joyenjoyer joyenjoyer commented Aug 26, 2024

Closes: INSTUI-4190

Test:
Try expanding and closing ToggleDetails controlled and uncontrolled examples in our docs app. Observe if the component flickers.

I tested whether changing properties causes flickering or any other issues, it does not. You can use the below code for testing:

const Example = () => {
  const [state, setState] = useState({
    expanded: true,
    fluidWidth: true,
    iconPosition: 'start',
    size: 'small',
    variant: 'default'
  });

  const handleChange = (field, value) => setState(prevState => ({ ...prevState, [field]: value }));
  const handleToggle = () => setState(prevState => ({ ...prevState, expanded: !prevState.expanded }));

  const renderOptions = () => {
    const { fluidWidth, iconPosition, size, variant } = state;
    const options = [
      { name: 'iconPosition', values: ['start', 'end'] },
      { name: 'size', values: ['small', 'medium', 'large'] },
      { name: 'variant', values: ['default', 'filled'] },
    ];

    return (
      <Flex alignItems="start">
        {options.map(({ name, values }) => (
          <Flex.Item margin="small" key={name}>
            <RadioInputGroup
              name={name}
              description={name}
              value={state[name]}
              onChange={(e, value) => handleChange(name, value)}
            >
              {values.map(val => (
                <RadioInput label={val} value={val} key={val} />
              ))}
            </RadioInputGroup>
          </Flex.Item>
        ))}
        <Flex.Item margin="small">
          <Checkbox
            label="fluidWidth"
            checked={fluidWidth}
            onChange={() => handleChange('fluidWidth', !fluidWidth)}
          />
        </Flex.Item>
      </Flex>
    );
  };

  const { expanded, iconPosition, size, variant, fluidWidth } = state;

  return (
    <div>
      {renderOptions()}
      <Button onClick={handleToggle}>
        This Button {expanded ? 'Collapses' : 'Expands'}
      </Button>
      <br />
      <br />
      <ToggleDetails
        summary="Click to hide me!"
        expanded={expanded}
        onToggle={(_, expanded) => handleChange('expanded', expanded)}
        fluidWidth={fluidWidth}
        iconPosition={iconPosition}
        size={size}
        variant={variant}
      >
        <Text weight="bold">
          I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!
        </Text>
      </ToggleDetails>
    </div>
  );
};

render(<Example />)

@joyenjoyer joyenjoyer self-assigned this Aug 26, 2024
@joyenjoyer joyenjoyer force-pushed the INSTUI-4190-toggle-details-is-sometimes-flickering branch 2 times, most recently from 4444b0e to 1239a04 Compare August 26, 2024 13:34
Copy link

github-actions bot commented Aug 26, 2024

PR Preview Action v1.4.7
🚀 Deployed preview to https://instructure.github.io/instructure-ui/pr-preview/pr-1651/
on branch gh-pages at 2024-09-03 15:56 UTC

@matyasf
Copy link
Collaborator

matyasf commented Aug 28, 2024

I dont see any flickering in the examples even before this fix. Can you please link an example where the difference if visible? Thanks!

// will animate the details
if (prevProps.expanded !== this.props.expanded) {
this.props.makeStyles?.({ animate: true } as ToggleDetailsStyleProps)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create an example app where changing other properties (used in styles.ts) can be tested for this logic.

@joyenjoyer joyenjoyer force-pushed the INSTUI-4190-toggle-details-is-sometimes-flickering branch 2 times, most recently from 11cb9ed to bca2725 Compare September 3, 2024 11:22
@joyenjoyer joyenjoyer force-pushed the INSTUI-4190-toggle-details-is-sometimes-flickering branch from bca2725 to fee93f8 Compare September 3, 2024 15:50
@joyenjoyer joyenjoyer merged commit cbab3be into master Sep 3, 2024
9 checks passed
@joyenjoyer joyenjoyer deleted the INSTUI-4190-toggle-details-is-sometimes-flickering branch September 3, 2024 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants