Skip to content

Commit

Permalink
fix: select keyboard navigation + refactor unit tests (siemens#1648)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasBerliner authored Jan 16, 2025
1 parent 9a5fff6 commit 1625ddc
Show file tree
Hide file tree
Showing 7 changed files with 550 additions and 342 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-carrots-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siemens/ix': patch
---

Fix **ix-select** keyboard navigation and wrap behavior when new items are created
2 changes: 1 addition & 1 deletion packages/core/playwright-ct.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const config: PlaywrightTestConfig = {
},
},
],
retries: 2,
retries: 3,
};

export default config;
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ test('valid color with valid textarea field', async ({ mount, page }) => {

test('invalid color with invalid textarea field', async ({ mount, page }) => {
await mount(`
<ix-textarea label="invalid label text" required>valid field</ix-textarea>
<ix-textarea label="invalid label text" required>invalid field</ix-textarea>
`);

const fieldElement = page.locator('ix-textarea');
const labelElement = page.locator('ix-field-label');

await expect(fieldElement).not.toHaveClass(/ix-invalid--required/);
await expect(fieldElement).toHaveClass(/ix-invalid--required/);

await expect(labelElement.locator('ix-typography')).toHaveAttribute(
'style',
Expand Down
23 changes: 15 additions & 8 deletions packages/core/src/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,6 @@ export class Select implements IxInputFieldComponent<string | string[]> {
@Watch('dropdownShow')
watchDropdownShow(show: boolean) {
if (show && this.dropdownElement) {
this.arrowFocusController = new ArrowFocusController(
this.visibleNonShadowItems,
this.dropdownElement,
this.focusControllerCallbackBind
);

this.arrowFocusController.wrap = !this.editable;

this.itemObserver.observe(this.dropdownElement, {
childList: true,
subtree: true,
Expand Down Expand Up @@ -494,6 +486,21 @@ export class Select implements IxInputFieldComponent<string | string[]> {
this.updateFormInternalValue(this.value);
}

componentDidRender(): void {
if (!this.dropdownShow || this.arrowFocusController) {
return;
}

this.arrowFocusController = new ArrowFocusController(
this.visibleNonShadowItems,
this.dropdownElement,
this.focusControllerCallbackBind
);

this.arrowFocusController.wrap =
!this.isAddItemVisible() && !this.visibleShadowItems.length;
}

@Listen('ix-select-item:valueChange')
@Listen('ix-select-item:labelChange')
onLabelChange(event: IxSelectItemLabelChangeEvent) {
Expand Down
Loading

0 comments on commit 1625ddc

Please sign in to comment.