Skip to content

Commit 34e8a71

Browse files
Fix/hide-singleselect-clear-on-disabled (#1195)
* 🐛 Prevent ClearButton from rendering when SearchBar is disabled * 🔖 Bump version to 10.8.2 in package.json * ♻️ Update DisabledSingleSelect story with default value and onSelect handler * ♻️ Update DisabledSingleSelect story to set default value and check for clear button
1 parent 8f2ab88 commit 34e8a71

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@equinor/amplify-component-lib",
3-
"version": "10.8.1",
3+
"version": "10.8.2",
44
"description": "Frontend Typescript components for the Amplify team",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/molecules/Select/SearchBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export const SearchBar = <T extends SelectOptionRequired>({
195195
}
196196
/>
197197
)}
198-
{clearable && selectedValues.length > 0 && !loading && (
198+
{clearable && selectedValues.length > 0 && !loading && !disabled && (
199199
<ClearButton
200200
id="clear"
201201
variant="ghost_icon"

src/molecules/Select/SingleSelect/SingleSelect.stories.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { FC, useState } from 'react';
33
import { Icon } from '@equinor/eds-core-react';
44
import { boat, car, flight } from '@equinor/eds-icons';
55
import { faker } from '@faker-js/faker';
6-
import { Meta, StoryFn } from '@storybook/react-vite';
6+
import { Meta, StoryFn, StoryObj } from '@storybook/react-vite';
77

88
import { colors, spacings } from 'src/atoms/style';
99
import {
@@ -14,6 +14,7 @@ import {
1414
import { SingleSelect } from 'src/molecules/Select/SingleSelect/SingleSelect';
1515

1616
import { actions } from 'storybook/actions';
17+
import { expect } from 'storybook/test';
1718

1819
const meta: Meta<typeof SingleSelect> = {
1920
title: 'Molecules/Select/SingleSelect',
@@ -260,3 +261,22 @@ export const SingleSelectWithCustomValueComponent: StoryFn = (args) => {
260261
/>
261262
);
262263
};
264+
265+
type Story = StoryObj<typeof SingleSelect>;
266+
267+
export const DisabledSingleSelect: Story = {
268+
args: {
269+
disabled: true,
270+
items: FAKE_ITEMS,
271+
value: FAKE_ITEMS[0],
272+
onSelect: () => {},
273+
},
274+
play: async ({ canvas, step }) => {
275+
await step('Verify that the select is disabled', () => {
276+
expect(canvas.getByRole('combobox')).toBeDisabled();
277+
});
278+
await step('Verify that the clear button is not rendered', () => {
279+
expect(canvas.queryByTestId('clearBtn')).not.toBeInTheDocument();
280+
});
281+
},
282+
};

0 commit comments

Comments
 (0)