Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed highlight from Dropdown components #16789

Merged
merged 18 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions e2e/components/ComboBox/ComboBox-test.avt.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ test.describe('@avt ComboBox', () => {
await expect(combobox).toBeFocused();
await page.keyboard.press('Enter');
await expect(menu).toBeVisible();
await page.keyboard.press('ArrowDown');
// Navigation inside the menu
// move to first option
await expect(optionOne).toHaveClass(
Expand Down Expand Up @@ -122,15 +123,17 @@ test.describe('@avt ComboBox', () => {
await page.keyboard.press('Enter');
await page.keyboard.press('ArrowDown');
await page.keyboard.press('Enter');
await expect(combobox).toHaveValue('Option 1');
await expect(combobox).toHaveValue(
'An example option that is really long to show what should be done to handle long text'
);
await page.keyboard.press('Escape');

// should open and select option 2
await page.keyboard.press('Enter');
await page.keyboard.press('ArrowDown');
await page.keyboard.press('ArrowDown');
await page.keyboard.press('Enter');
await expect(combobox).toHaveValue('Option 2');
await expect(combobox).toHaveValue('Option 1');
await page.keyboard.press('Escape');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ test.describe('@avt FluidComboBox', () => {
await expect(combobox).toBeFocused();
await page.keyboard.press('Enter');
await expect(menu).toBeVisible();
await page.keyboard.press('ArrowDown');
// Navigation inside the menu
// move to first option
await expect(optionOne).toHaveClass(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ test.describe('@avt FluidMultiSelect', () => {
await expect(toggleButton).toBeFocused();
await page.keyboard.press('Space');
await expect(menu).toBeVisible();
await page.keyboard.press('ArrowDown');
// Navigation inside the menu
// Focus on first element by default
await expect(
Expand Down Expand Up @@ -175,6 +176,7 @@ test.describe('@avt FluidMultiSelect', () => {
await expect(toggleButton).toBeFocused();
await page.keyboard.press('Space');
await expect(menu).toBeVisible();
await page.keyboard.press('ArrowDown');
// Navigation inside the menu
// Focus on first element by default
await expect(
Expand Down
11 changes: 6 additions & 5 deletions e2e/components/MultiSelect/MultiSelect-test.avt.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ test.describe('@avt MultiSelect', () => {
page.getByRole('option', {
name: 'An example option that is really long to show what should be done to handle long text',
})
).toHaveClass(
).not.toHaveClass(
'cds--list-box__menu-item cds--list-box__menu-item--highlighted'
);
// select first option (should select with enter and space)
await page.keyboard.press('ArrowDown');
await page.keyboard.press('Enter');
await expect(
page.getByRole('option', {
Expand Down Expand Up @@ -210,22 +211,22 @@ test.describe('@avt MultiSelect', () => {
page.getByRole('option', {
name: 'An example option that is really long to show what should be done to handle long text',
})
).toHaveClass(
).not.toHaveClass(
'cds--list-box__menu-item cds--list-box__menu-item--highlighted'
);
// select first option (should only select with enter)
await page.keyboard.press('Enter');
await expect(
page.getByRole('option', {
name: 'An example option that is really long to show what should be done to handle long text',
selected: true,
selected: false,
})
).toBeVisible();
// move to second option
await page.keyboard.press('ArrowDown');
await expect(
page.getByRole('option', {
name: 'Option 1',
name: 'An example option that is really long to show what should be done to handle long text',
})
).toHaveClass(
'cds--list-box__menu-item cds--list-box__menu-item--highlighted'
Expand All @@ -234,7 +235,7 @@ test.describe('@avt MultiSelect', () => {
await page.keyboard.press('Enter');
await expect(
page.getByRole('option', {
name: 'Option 1',
name: 'An example option that is really long to show what should be done to handle long text',
selected: true,
})
).toBeVisible();
Expand Down
10 changes: 5 additions & 5 deletions e2e/components/Toggle/Toggle-test.avt.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ test.describe('@avt Toggle', () => {
theme: 'white',
},
});
const toggleSwitch = page.getByRole('switch');
await page.keyboard.press('Tab');
await expect(page.getByRole('switch')).toBeVisible();
await page.keyboard.press('Space');
page.getByText('Off');
await page.keyboard.press('Space');
page.getByText('On');
await expect(toggleSwitch).toBeVisible();
await expect(toggleSwitch).toHaveAttribute('aria-checked', 'true');
await page.keyboard.press('Enter');
await expect(toggleSwitch).toHaveAttribute('aria-checked', 'false');
});
});
2 changes: 1 addition & 1 deletion packages/react/src/components/ComboBox/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ const ComboBox = forwardRef(
case FunctionToggleMenu:
case ToggleButtonClick:
if (changes.isOpen && !changes.selectedItem) {
return { ...changes, highlightedIndex: 0 };
return { ...changes };
}
return changes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ const FilterableMultiSelect = React.forwardRef(function FilterableMultiSelect<
} = useCombobox<ItemType>({
isOpen,
items: sortedItems,
defaultHighlightedIndex: topItems.length > 0 ? 0 : undefined, // after selection, highlight the first item.
itemToString,
defaultHighlightedIndex: 0, // after selection, highlight the first item.
id,
labelId,
menuId,
Expand All @@ -494,7 +494,6 @@ const FilterableMultiSelect = React.forwardRef(function FilterableMultiSelect<
return (item as any).disabled;
},
});

function stateReducer(state, actionAndChanges) {
const { type, props, changes } = actionAndChanges;
const { highlightedIndex } = changes;
Expand Down Expand Up @@ -523,7 +522,7 @@ const FilterableMultiSelect = React.forwardRef(function FilterableMultiSelect<
case FunctionToggleMenu:
case ToggleButtonClick:
if (changes.isOpen && !changes.selectedItem) {
return { ...changes, highlightedIndex: 0 };
return { ...changes };
}
return changes;
case InputChange:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ const MultiSelect = React.forwardRef(
break;
case ToggleButtonClick:
setIsOpenWrapper(changes.isOpen || false);
return { ...changes, highlightedIndex: 0 };
return { ...changes };
case ItemClick:
setHighlightedIndex(changes.selectedItem);
onItemChange(changes.selectedItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ describe('MultiSelect', () => {

expect(itemNode).toHaveAttribute('data-contained-checkbox-state', 'false');

await userEvent.keyboard('[Enter]');
await userEvent.keyboard('[ArrowDown]');
await userEvent.keyboard('[Enter]');

expect(itemNode).toHaveAttribute('data-contained-checkbox-state', 'true');
Expand Down
4 changes: 3 additions & 1 deletion packages/styles/scss/components/combo-box/_combo-box.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
}

.#{$prefix}--list-box--expanded
.#{$prefix}--combo-box--input--focus.#{$prefix}--text-input {
.#{$prefix}--combo-box--input--focus.#{$prefix}--text-input:not(
.#{$prefix}--text-input--empty
) {
outline-offset: convert.to-rem(-1px);
outline-width: convert.to-rem(1px);
}
Expand Down
Loading