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

CustomSelectControlV2: animate select popover appearance #63343

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Internal

- `CustomSelectControlV2`: animate select popover appearance. ([#63343](https://github.com/WordPress/gutenberg/pull/63343))

## 28.3.0 (2024-07-10)

### Enhancements
Expand Down
31 changes: 28 additions & 3 deletions packages/components/src/custom-select-control-v2/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import * as Ariakit from '@ariakit/react';
import { css } from '@emotion/react';
import { css, keyframes } from '@emotion/react';
import styled from '@emotion/styled';
/**
* Internal dependencies
Expand All @@ -13,6 +13,13 @@ import { chevronIconSize } from '../select-control/styles/select-control-styles'
import { fontSizeStyles } from '../input-control/styles/input-control-styles';
import type { CustomSelectButtonSize } from './types';

// TODO: extract to common utils and apply to relevant components
const ANIMATION_PARAMS = {
SLIDE_AMOUNT: '2px',
Copy link
Member

Choose a reason for hiding this comment

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

Should this be increased in order to make it more obvious that the select options are dropping down?

Copy link
Member

Choose a reason for hiding this comment

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

Now that you changed it to starting from - SLIDE_AMOUNT, it looks good actually 👍 Nice touch!

DURATION: '400ms',
EASING: 'cubic-bezier( 0.16, 1, 0.3, 1 )',
};

const INLINE_PADDING = {
compact: 8, // space(2)
small: 8, // space(2)
Expand Down Expand Up @@ -98,6 +105,14 @@ export const Select = styled( Ariakit.Select, {
`
);

const slideDownAndFade = keyframes( {
'0%': {
opacity: 0,
transform: `translateY(-${ ANIMATION_PARAMS.SLIDE_AMOUNT })`,
},
'100%': { opacity: 1, transform: 'translateY(0)' },
} );

export const SelectPopover = styled( Ariakit.SelectPopover )`
display: flex;
flex-direction: column;
Expand All @@ -113,11 +128,21 @@ export const SelectPopover = styled( Ariakit.SelectPopover )`
overflow: auto;
overscroll-behavior: contain;

// The smallest size without overflowing the container.
/* The smallest size without overflowing the container. */
min-width: min-content;

/* Animation */
animation-duration: ${ ANIMATION_PARAMS.DURATION };
animation-timing-function: ${ ANIMATION_PARAMS.EASING };
animation-name: ${ slideDownAndFade };
will-change: transform, opacity;
@media ( prefers-reduced-motion ) {
animation-duration: 0s;
}

&[data-focus-visible] {
outline: none; // outline will be on the trigger, rather than the popover
/* The outline will be on the trigger, rather than the popover. */
outline: none;
}
`;

Expand Down
Loading