Skip to content

Commit de5bc95

Browse files
nsdeschenesandrewshie-sentry
authored andcommitted
feat(search-bar): Update dropdowns to loop around when using arrows (#97607)
This PR updates the combobox dropdowns to loop when hitting the top or bottom items in the list, similar to the behaviour of the larger suggestion dropdown that first appears when entering the input. This PR also removes uses cases `space` and moves them to their theme equivalent in touched files.
1 parent 397df6d commit de5bc95

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed

static/app/components/searchQueryBuilder/index.spec.tsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,6 +1590,59 @@ describe('SearchQueryBuilder', function () {
15901590
const updatedListBox = screen.getByRole('checkbox', {name: 'Toggle randomValue'});
15911591
expect(updatedListBox).toBeChecked();
15921592
});
1593+
1594+
describe('filter key combobox', function () {
1595+
it.each([
1596+
{
1597+
description: 'goes to first item when pressing arrow down',
1598+
arrow: '{ArrowDown}',
1599+
expected: 'option-age',
1600+
},
1601+
{
1602+
description: 'goes to last item when pressing arrow up',
1603+
arrow: '{ArrowUp}',
1604+
expected: 'option-custom_tag_name',
1605+
},
1606+
{
1607+
description: 'goes to first item when pressing arrow down on the last item',
1608+
arrow: '{ArrowDown}{ArrowUp}',
1609+
expected: 'option-custom_tag_name',
1610+
},
1611+
{
1612+
description: 'goes to last item when pressing arrow up on the first item',
1613+
arrow: '{ArrowUp}{ArrowDown}',
1614+
expected: 'option-age',
1615+
},
1616+
{
1617+
description: 'goes to the last item after going from second up to first',
1618+
arrow: '{ArrowDown}{ArrowDown}{ArrowUp}{ArrowUp}',
1619+
expected: 'option-custom_tag_name',
1620+
},
1621+
{
1622+
description:
1623+
'goes to the first item after going from second last item up to first',
1624+
arrow: '{ArrowUp}{ArrowUp}{ArrowDown}{ArrowDown}',
1625+
expected: 'option-age',
1626+
},
1627+
])('$description', async function ({arrow, expected}) {
1628+
render(
1629+
<SearchQueryBuilder {...defaultProps} initialQuery="browser.name:Firefox" />
1630+
);
1631+
1632+
await userEvent.click(
1633+
screen.getByRole('button', {name: 'Edit key for filter: browser.name'})
1634+
);
1635+
1636+
await userEvent.clear(screen.getByRole('combobox', {name: 'Edit filter key'}));
1637+
1638+
await userEvent.keyboard(arrow);
1639+
const input = await screen.findByRole('combobox', {name: 'Edit filter key'});
1640+
expect(input).toHaveAttribute(
1641+
'aria-activedescendant',
1642+
expect.stringContaining(expected)
1643+
);
1644+
});
1645+
});
15931646
});
15941647

15951648
describe('token values', function () {

static/app/components/searchQueryBuilder/tokens/combobox.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ export function SearchQueryBuilderCombobox<
423423
listBoxRef,
424424
inputRef,
425425
popoverRef,
426+
shouldFocusWrap: true,
426427
onFocus: e => {
427428
if (openOnFocus) {
428429
state.open();

static/app/components/searchQueryBuilder/tokens/filter/valueCombobox.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ import {
5353
} from 'sentry/components/searchSyntax/parser';
5454
import {getKeyName} from 'sentry/components/searchSyntax/utils';
5555
import {t} from 'sentry/locale';
56-
import {space} from 'sentry/styles/space';
5756
import type {Tag, TagCollection} from 'sentry/types/group';
5857
import {trackAnalytics} from 'sentry/utils/analytics';
5958
import {uniq} from 'sentry/utils/array/uniq';
@@ -966,13 +965,16 @@ const TrailingWrap = styled('div')`
966965
display: grid;
967966
grid-auto-flow: column;
968967
align-items: center;
969-
gap: ${space(1)};
968+
gap: ${p => p.theme.space.md};
970969
`;
971970

972971
const CheckWrap = styled('div')<{visible: boolean}>`
973972
display: flex;
974973
justify-content: center;
975974
align-items: center;
976975
opacity: ${p => (p.visible ? 1 : 0)};
977-
padding: ${space(0.25)} 0 ${space(0.25)} ${space(0.25)};
976+
padding-top: ${p => p.theme.space['2xs']};
977+
padding-right: 0;
978+
padding-bottom: ${p => p.theme.space['2xs']};
979+
padding-left: ${p => p.theme.space['2xs']};
978980
`;

static/app/components/tokenizedInput/token/comboBox.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ export function ComboBox({
228228
listBoxRef,
229229
inputRef,
230230
popoverRef,
231+
shouldFocusWrap: true,
231232
onFocus: handleComboBoxFocus,
232233
onBlur: handleComboBoxBlur,
233234
onKeyDown: handleComboBoxKeyDown,

0 commit comments

Comments
 (0)