Skip to content

Commit

Permalink
fix: ensure shortcuts are not ignored when the focused element is a r…
Browse files Browse the repository at this point in the history
…adio or checkbox
  • Loading branch information
hamed-musallam committed Sep 13, 2024
1 parent 1ae01cd commit e8f3667
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/component/EventsTrackers/KeysListenerTracker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ function KeysListenerTracker(props: KeysListenerTrackerProps) {

const handleOnKeyDown = useCallback(
(e) => {
if (checkNotInputField(e) && mouseIsOverDisplayer.current) {
if (!ignoreElement(e) && mouseIsOverDisplayer.current) {
const num = Number(e.code.slice(-1)) || 0;
if (num > 0) {
keysPreferencesListenerHandler(e, num);
Expand Down Expand Up @@ -523,13 +523,15 @@ function KeysListenerTracker(props: KeysListenerTrackerProps) {
<SaveAsModal isOpen={isSaveModalOpened} onCloseDialog={closeSaveAsDialog} />
);
}
const tags = new Set(['INPUT', 'TEXTAREA']);
const inputTypes = new Set(['checkbox', 'radio']);

function checkNotInputField(e: Event) {
const tags = ['input', 'textarea'];
const tagName = (e.composedPath()[0] as HTMLElement).tagName.toLowerCase();
if (!tags.includes(tagName)) return true;

return false;
function ignoreElement(e: Event) {
const element = e.target as HTMLInputElement;
return (
(tags.has(element.tagName) && !inputTypes.has(element.type)) ||
element.isContentEditable
);
}

export default KeysListenerTracker;

0 comments on commit e8f3667

Please sign in to comment.