Skip to content

Commit bb26ccc

Browse files
committed
style: replace NoItemsFoundText with PersistentNoItemsFoundText to prevent layout shift
1 parent 640e873 commit bb26ccc

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

src/molecules/Select/GroupedSelectPersistent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { SelectOptionRequired } from 'src/molecules';
44
import { useGroupedSelectItems } from 'src/molecules/Select/Select.hooks';
55
import {
66
GroupTitle,
7-
NoItemsFoundText,
87
PersistentGroupsWrapper,
8+
PersistentNoItemsFoundText,
99
} from 'src/molecules/Select/Select.styles';
1010
import {
1111
CustomMenuItemComponentProps,
@@ -38,7 +38,7 @@ export const GroupedSelectPersistent = <T extends SelectOptionRequired>(
3838
const { filteredGroups, filteredGroupSum } = useGroupedSelectItems(props);
3939

4040
if (filteredGroups.length === 0) {
41-
return <NoItemsFoundText>No items found</NoItemsFoundText>;
41+
return <PersistentNoItemsFoundText>No items found</PersistentNoItemsFoundText>;
4242
}
4343

4444
// This case never happens, since there is a check in select.tsx. This check gives the correct typescript inference.

src/molecules/Select/ListSelectPersistent.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { capitalize } from 'src/atoms';
33
import { useListSelectItems } from 'src/molecules/Select/Select.hooks';
44
import {
55
GroupTitle,
6-
NoItemsFoundText,
76
NoTagFoundText,
7+
PersistentNoItemsFoundText,
88
} from 'src/molecules/Select/Select.styles';
99
import {
1010
CustomMenuItemComponentProps,
@@ -40,7 +40,9 @@ export const ListSelectPersistent = <T extends SelectOptionRequired>(
4040
const { filteredItems } = useListSelectItems(props);
4141

4242
if (filteredItems.length === 0 && (!props.onAddItem || search === '')) {
43-
return <NoItemsFoundText>No items found</NoItemsFoundText>;
43+
return (
44+
<PersistentNoItemsFoundText>No items found</PersistentNoItemsFoundText>
45+
);
4446
}
4547

4648
const hasNestedItems = filteredItems.some(

src/molecules/Select/Select.styles.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { Chip } from 'src/molecules/Chip/Chip';
1010

1111
import styled, { css } from 'styled-components';
1212

13+
// Persistent mode keeps an explicit item height so the empty state matches without layout shift
14+
const PERSISTENT_ITEM_HEIGHT = '56px'; // PersistentListItem: 2×spacings.medium padding + 24px line-height
15+
1316
interface WrapperProps {
1417
$showBackgroundColor: boolean;
1518
}
@@ -320,6 +323,7 @@ const PersistentListItem = styled.button`
320323
padding: ${spacings.medium} ${spacings.medium};
321324
justify-content: flex-start;
322325
gap: ${spacings.small};
326+
min-height: ${PERSISTENT_ITEM_HEIGHT};
323327
box-sizing: border-box;
324328
svg {
325329
flex-shrink: 0;
@@ -366,12 +370,19 @@ const NoTagFoundText = styled(Typography)`
366370
margin: ${spacings.medium};
367371
`;
368372

369-
const NoItemsFoundText = styled(Typography)`
373+
const NoItemsFoundText = styled(Typography).attrs({
374+
group: 'navigation',
375+
variant: 'menu_title',
376+
})`
370377
display: flex;
371378
align-items: center;
372379
margin: 0;
373380
padding: ${spacings.medium};
374-
min-height: 56px; // Height of one menu item to avoid layout shift
381+
box-sizing: border-box;
382+
`;
383+
384+
const PersistentNoItemsFoundText = styled(NoItemsFoundText)`
385+
min-height: ${PERSISTENT_ITEM_HEIGHT};
375386
`;
376387

377388
const StyledMenu = styled(EDSMenu)`
@@ -407,6 +418,7 @@ export {
407418
StyledMenu,
408419
NoTagFoundText,
409420
NoItemsFoundText,
421+
PersistentNoItemsFoundText,
410422
PlaceholderText,
411423
PersistentListItem,
412424
PersistentComboBoxWrapper,

0 commit comments

Comments
 (0)