@fluentui/react-northstar
Version:
A themable React component library.
16 lines (15 loc) • 725 B
JavaScript
import { getCode, SpacebarKey, EnterKey } from '@fluentui/accessibility';
/**
* Checks if `preventDefault()` should be called for a passed keyboard event.
*/
export function shouldPreventDefaultOnKeyDown(e) {
var code = getCode(e);
var target = e.target;
var matchesByKey = code === SpacebarKey || code === EnterKey;
if ((target == null ? void 0 : target.tagName) === 'A') {
return code === SpacebarKey;
}
var ignoredByTag = (target == null ? void 0 : target.tagName) === 'INPUT' || (target == null ? void 0 : target.tagName) === 'TEXTAREA' || (target == null ? void 0 : target.isContentEditable) === true;
return matchesByKey && !ignoredByTag;
}
//# sourceMappingURL=shouldPreventDefaultOnKeyDown.js.map