Skip to content

Conversation

jcfilben
Copy link
Collaborator

What does this PR do?

Fixes an issue where Drop's scroll position gets reset after a style change occurs in the drop.

The solution separates existing code from one useEffect into two useEffects

Where should the reviewer start?

What testing has been done on this PR?

Tested with the following story:

import React, { useState } from 'react';
import { Close } from 'grommet-icons';

import { Box, Button, DropButton, Heading } from 'grommet';

const align = { top: 'bottom' };

const SimpleDropButton = () => {
  const [open, setOpen] = React.useState();
  const [hover, setHover] = useState(false);
  const onOpen = () => {
    setOpen(true);
  };
  const onClose = () => {
    setOpen(false);
  };

  return (
    <Box align="center" pad="large">
      <DropButton
        label="Open"
        open={open}
        onOpen={onOpen}
        onClose={onClose}
        dropContent={
          <Box pad="small">
            <Box
              onMouseOver={() => setHover(true)}
              onMouseLeave={() => setHover(false)}
              justify="between"
              align="center"
            >
              <Heading
                style={{ backgroundColor: hover ? 'yellow' : undefined }}
                level={3}
                margin="small"
              >
                Heading
              </Heading>
              <Heading level={3} margin="small">
                Heading
              </Heading>
              <Heading level={3} margin="small">
                Heading
              </Heading>
              <Heading level={3} margin="small">
                Heading
              </Heading>
              <Heading level={3} margin="small">
                Heading
              </Heading>
              <Heading level={3} margin="small">
                Heading
              </Heading>
              <Heading level={3} margin="small">
                Heading
              </Heading>
              <Heading level={3} margin="small">
                Heading
              </Heading>
              <Button icon={<Close />} onClick={onClose} />
            </Box>
          </Box>
        }
        dropProps={{ align }}
      />
    </Box>
  );
};

export const Simple = () => <SimpleDropButton />;
Simple.parameters = {
  chromatic: { disable: true },
};

export default {
  title: 'Controls/DropButton/Simple',
};

How should this be manually tested?

Do Jest tests follow these best practices?

  • screen is used for querying.
  • The correct query is used. (Refer to this list of queries)
  • userEvent is used in place of fireEvent.
  • asFragment() is used for snapshot testing.

Any background context you want to provide?

What are the relevant issues?

Closes #6334

Screenshots (if appropriate)

Do the grommet docs need to be updated?

No

Should this PR be mentioned in the release notes?

Yes

Is this change backwards compatible or is it a breaking change?

Backwards compatible

@jcfilben jcfilben requested a review from taysea January 12, 2023 22:06
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.

Scroll Position Getting Reset On Hover with DropButton
2 participants