Skip to content

Commit

Permalink
Merge pull request #2255 from ing-bank/fix/dropdown-tel
Browse files Browse the repository at this point in the history
fix: optimize the way we focus the input field for LionInputTelDropdown
  • Loading branch information
okadurin authored Apr 16, 2024
2 parents 29104e8 + ac78346 commit ffa0bd5
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 44 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-lemons-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lion/ui': patch
---

[lion-input-tel-dropdown] Focus input fieled after dropdown menu is closed
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export class IntlInputTelDropdown extends ScopedElementsMixin(LionInputTelDropdo
${ref(refs?.dropdown?.ref)}
label="${refs?.dropdown?.labels?.country}"
label-sr-only
.config="${{ elementToFocusAfterHide: refs?.input }}"
@model-value-changed="${refs?.dropdown?.listeners['model-value-changed']}"
style="${refs?.dropdown?.props?.style}"
>
Expand Down
130 changes: 99 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@custom-elements-manifest/analyzer": "^0.8.0",
"@open-wc/building-rollup": "^1.10.0",
"@open-wc/eslint-config": "^10.0.0",
"@open-wc/scoped-elements": "^3.0.5",
"@open-wc/testing": "^3.1.7",
"@open-wc/testing-helpers": "^2.2.0",
"@rocket/blog": "^0.4.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export class LionInputTelDropdown extends LionInputTel {
localizeManager.msg('lion-input-tel:suggestedCountries'),
},
},
input: this._inputNode,
};

return {
Expand Down Expand Up @@ -357,19 +358,6 @@ export class LionInputTelDropdown extends LionInputTel {
}
}
}

// Put focus on text box
//
// A LionSelectRich with interactionMode set on windows/linux
// will set each item on arrow key up/down to activeElement
// which causes the focus to jump every time to the inputNode
const overlayController = dropdownElement._overlayCtrl;
// @ts-ignore interactionMode only exists on LionSelectRich not on HTMLSelectElement
if (overlayController?.isShown && dropdownElement.interactionMode !== 'windows/linux') {
setTimeout(() => {
this._inputNode.focus();
});
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ export function runInputTelDropdownSuite({ klass } = { klass: LionInputTelDropdo
props: { style: 'height: 100%;' },
ref: { value: dropdownNode },
},
// @ts-expect-error [allow-protected]
input: el._inputNode,
},
}),
);
Expand Down
1 change: 1 addition & 0 deletions packages/ui/components/input-tel-dropdown/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type TemplateDataForDropdownInputTel = {
};
labels: { selectCountry: string };
};
input: HTMLInputElement;
};
data: {
activeRegion: string | undefined;
Expand Down

0 comments on commit ffa0bd5

Please sign in to comment.