Skip to content

Commit 59a1346

Browse files
randall-krauskopffrancineluccahussam-i-am
authored
feat(Autocomplete): Convert Box usage to CSS modules behind feature flag (#5451)
* test(AutoComplete): add e2e tests * test(vrt): update snapshots * fix(Autocomplete): wait for full render before e2e testing * test(vrt): update snapshots * fix dev storybook accessibility * fix lint * fix theme related a11y errors * test(vrt): update snapshots * ignore color-contrast rule * initial commit * remove unused snapshots * remove file * revert file * format fix * changeset --------- Co-authored-by: Marie Lucca <[email protected]> Co-authored-by: francinelucca <[email protected]> Co-authored-by: Marie Lucca <[email protected]> Co-authored-by: randall-krauskopf <[email protected]> Co-authored-by: Hussam Ghazzi <[email protected]>
1 parent e1808ec commit 59a1346

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

.changeset/purple-pants-sit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": minor
3+
---
4+
5+
Convert Box usage in Autocomplete to CSS modules behind feature flag
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.SpinnerWrapper {
2+
display: flex;
3+
justify-content: center;
4+
padding: var(--base-size-16);
5+
}
6+
7+
.EmptyStateWrapper {
8+
padding: var(--base-size-16);
9+
}

packages/react/src/Autocomplete/AutocompleteMenu.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import type {IconProps} from '@primer/octicons-react'
1313
import {PlusIcon} from '@primer/octicons-react'
1414
import VisuallyHidden from '../_VisuallyHidden'
1515
import {isElement} from 'react-is'
16+
import {useFeatureFlag} from '../FeatureFlags'
17+
18+
import classes from './AutocompleteMenu.module.css'
1619

1720
type OnSelectedChange<T> = (item: T | T[]) => void
1821
export type AutocompleteMenuItem = MandateProps<ActionListItemProps, 'id'> & {
@@ -117,6 +120,8 @@ export type AutocompleteMenuInternalProps<T extends AutocompleteItemProps> = {
117120
['aria-labelledby']: string
118121
}
119122

123+
const CSS_MODULES_FEATURE_FLAG = 'primer_react_css_modules_team'
124+
120125
function AutocompleteMenu<T extends AutocompleteItemProps>(props: AutocompleteMenuInternalProps<T>) {
121126
const autocompleteContext = useContext(AutocompleteContext)
122127
if (autocompleteContext === null) {
@@ -324,12 +329,20 @@ function AutocompleteMenu<T extends AutocompleteItemProps>(props: AutocompleteMe
324329
throw new Error('Autocomplete: selectionVariant "single" cannot be used with multiple selected items')
325330
}
326331

332+
const enabled = useFeatureFlag(CSS_MODULES_FEATURE_FLAG)
333+
327334
return (
328335
<VisuallyHidden isVisible={showMenu}>
329336
{loading ? (
330-
<Box p={3} display="flex" justifyContent="center">
331-
<Spinner />
332-
</Box>
337+
enabled ? (
338+
<Box className={classes.SpinnerWrapper}>
339+
<Spinner />
340+
</Box>
341+
) : (
342+
<Box p={3} display="flex" justifyContent="center">
343+
<Spinner />
344+
</Box>
345+
)
333346
) : (
334347
<div ref={listContainerRef}>
335348
{allItemsToRender.length ? (
@@ -367,7 +380,11 @@ function AutocompleteMenu<T extends AutocompleteItemProps>(props: AutocompleteMe
367380
})}
368381
</ActionList>
369382
) : emptyStateText !== false && emptyStateText !== null ? (
370-
<Box p={3}>{emptyStateText}</Box>
383+
enabled ? (
384+
<Box className={classes.EmptyStateWrapper}>{emptyStateText}</Box>
385+
) : (
386+
<Box p={3}>{emptyStateText}</Box>
387+
)
371388
) : null}
372389
</div>
373390
)}

0 commit comments

Comments
 (0)