Skip to content

Commit

Permalink
feature: Add animation to dropdown component (#975)
Browse files Browse the repository at this point in the history
* feat(dropdown): add animation prop and update class binding for dropdown states

* feat(dropdown): add animation control to dropdown stories

* feat(dropdown): enhance dropdown animations and update styles for better interaction

* feat(dropdown): add animation property to documentation

* test(table): update selector for right chevron button in pagination test

* test(dropdown): update snapshot due to change in border color

* feat(dropdown): set default animation to 'slide' in dropdown component
  • Loading branch information
ckrook authored Jan 21, 2025
1 parent 5066fe4 commit a740538
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
font: var(--tds-detail-02);
letter-spacing: var(--tds-detail-02-ls);
overflow-wrap: anywhere;
transition: background-color var(--tds-motion-duration-fast-02) var(--tds-motion-easing-scania);

&.selected {
background-color: var(--tds-dropdown-option-background-selected);
Expand Down Expand Up @@ -78,7 +79,6 @@
&.xs {
padding: 7px 16px 8px;
}

}
}

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/components/dropdown/dropdown-vars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
--tds-dropdown-border-bottom: var(--tds-grey-600);
--tds-dropdown-border-bottom-hover: var(--tds-grey-800);
--tds-dropdown-border-bottom-open: var(--tds-blue-400);
--tds-dropdown-border-bottom-hover: var(--tds-grey-868);
--tds-dropdown-value-color: var(--tds-grey-958);
--tds-dropdown-label-color: var(--tds-grey-958);
--tds-dropdown-label-inside-color: var(--tds-grey-958);
Expand Down
27 changes: 24 additions & 3 deletions packages/core/src/components/dropdown/dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,19 @@
.dropdown-select {
position: relative;

button {
transition: border-bottom-color var(--tds-motion-duration-fast-02)
var(--tds-motion-easing-scania);
}

button:focus {
border-bottom-color: var(--tds-dropdown-border-bottom);
}

button:hover {
border-bottom-color: var(--tds-dropdown-border-bottom-hover);
}

button {
border-bottom-color: var(--tds-dropdown-border-bottom);
}
Expand Down Expand Up @@ -161,10 +170,11 @@
margin-top: 1px;
width: 100%;
transform-origin: top;
transition: transform 0.2s ease-in-out;
box-shadow: rgb(0 0 0 / 10%) 0 2px 3px 0;
border-radius: var(--tds-dropdown-list-border-radius-down);
overflow-y: auto;
transform: scaleY(0);
pointer-events: none;
@include tds-scrollbar;

&.lg {
Expand Down Expand Up @@ -200,11 +210,22 @@

&.closed {
transform: scaleY(0);
visibility: hidden;
pointer-events: none;
}

&.open {
transform: scaleY(1);
visibility: visible;
opacity: 1;
pointer-events: auto;
}

&.animation-enter-slide {
transition: transform var(--tds-motion-duration-moderate-01) var(--tds-motion-easing-enter);
}

&.animation-exit-slide {
transition: transform var(--tds-motion-duration-moderate-01) var(--tds-motion-easing-exit);
}

.no-result {
Expand Down Expand Up @@ -238,7 +259,7 @@
}

tds-icon {
transition: transform 0.2s ease-in-out;
transition: transform var(--tds-motion-duration-fast-02) var(--tds-motion-easing-scania);

&.open {
transform: rotateZ(180deg);
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/components/dropdown/dropdown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ export default {
defaultValue: { summary: 'false' },
},
},
animation: {
name: 'Animation',
description: 'Animation of the Dropdown.',
control: {
type: 'radio',
},
options: ['none', 'slide'],
table: {
defaultValue: { summary: 'Slide' },
},
},
filter: {
name: 'Filter',
description: 'Adds filter functionality to the Dropdown.',
Expand Down Expand Up @@ -178,6 +189,7 @@ export default {
disabled: false,
openDirection: 'Auto',
defaultOption: 'No default',
animation: 'slide',
},
};

Expand Down Expand Up @@ -220,6 +232,7 @@ const Template = ({
defaultOption,
multiDefaultOption,
noResultText,
animation,
}) =>
formatHtmlPreview(`
<style>
Expand Down Expand Up @@ -264,6 +277,7 @@ const Template = ({
${normalizeText ? '' : `normalize-text="false"`}
${multiselect ? 'multiselect' : ''}
${disabled ? 'disabled' : ''}
${animation !== 'None' ? `animation="${animation}"` : ''}
open-direction="${openDirection.toLowerCase()}"
>
<tds-dropdown-option value="option-1">
Expand Down
27 changes: 21 additions & 6 deletions packages/core/src/components/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export class TdsDropdown {
/** The size of the Dropdown. */
@Prop() size: 'xs' | 'sm' | 'md' | 'lg' = 'lg';

@Prop() animation: 'none' | 'slide' = 'slide';

/** Sets the Dropdown in an error state */
@Prop() error: boolean = false;

Expand Down Expand Up @@ -555,7 +557,15 @@ export class TdsDropdown {
}
this.handleBlur(event);
}}
onFocus={(event) => this.handleFocus(event)}
onFocus={(event) => {
this.open = true;
this.filterFocus = true;
if (this.multiselect) {
this.inputElement.value = '';
}
this.handleFocus(event);
this.handleFilter({ target: { value: '' } });
}}
onKeyDown={(event) => {
if (event.key === 'Escape') {
this.open = false;
Expand Down Expand Up @@ -641,11 +651,16 @@ export class TdsDropdown {
{/* DROPDOWN LIST */}
<div
ref={(element) => (this.dropdownList = element)}
class={`dropdown-list
${this.size}
${this.open ? 'open' : 'closed'}
${this.getOpenDirection()}
${this.label && this.labelPosition === 'outside' ? 'label-outside' : ''}`}
class={{
'dropdown-list': true,
[this.size]: true,
[this.getOpenDirection()]: true,
'label-outside': this.label && this.labelPosition === 'outside',
'open': this.open,
'closed': !this.open,
[`animation-enter-${this.animation}`]: this.animation !== 'none' && this.open,
[`animation-exit-${this.animation}`]: this.animation !== 'none' && !this.open,
}}
>
<slot onSlotchange={() => this.handleSlotChange()}></slot>
{this.filterResult === 0 && this.noResultText !== '' && (
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/components/dropdown/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

| Property | Attribute | Description | Type | Default |
| --------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | ------------- |
| `animation` | `animation` | | `"none" \| "slide"` | `'slide'` |
| `defaultValue` | `default-value` | Default value selected in the Dropdown. | `string` | `undefined` |
| `disabled` | `disabled` | Sets the Dropdown in a disabled state | `boolean` | `false` |
| `error` | `error` | Sets the Dropdown in an error state | `boolean` | `false` |
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test.describe.parallel('tds-table-pagination', () => {

test('Footer contains right chevron button, it is not disabled', async ({ page }) => {
await page.goto(componentTestPath);
const tableFooterRightChevronButton = page.getByRole('button').last();
const tableFooterRightChevronButton = page.getByRole('button').nth(2);
await expect(tableFooterRightChevronButton).toBeVisible();
await expect(tableFooterRightChevronButton).not.toHaveAttribute('disabled');
});
Expand Down

0 comments on commit a740538

Please sign in to comment.