profileSelector: Prevent wizard refresh on Enter key in OpenSCAP profile selector
Added event.preventDefault() in onKeyDown handler to stop default form submission behavior when hitting Enter in the typeahead filter. Also implemented auto-selection of single filtered results on Enter.
This commit is contained in:
parent
42d96edd00
commit
9e098f6aaf
1 changed files with 22 additions and 0 deletions
|
|
@ -274,6 +274,27 @@ const ProfileSelector = () => {
|
|||
}
|
||||
};
|
||||
|
||||
const onKeyDown = (event: React.KeyboardEvent) => {
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
|
||||
if (!isOpen) {
|
||||
setIsOpen(true);
|
||||
} else if (selectOptions.length === 1) {
|
||||
const singleProfile = selectOptions[0];
|
||||
const selection: OScapSelectOptionValueType = {
|
||||
profileID: singleProfile.id,
|
||||
toString: () => singleProfile.name || '',
|
||||
};
|
||||
|
||||
setInputValue(singleProfile.name || '');
|
||||
setFilterValue('');
|
||||
applyChanges(selection);
|
||||
setIsOpen(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const applyChanges = (selection: OScapSelectOptionValueType) => {
|
||||
if (selection.profileID === undefined) {
|
||||
// handle user has selected 'None' case
|
||||
|
|
@ -337,6 +358,7 @@ const ProfileSelector = () => {
|
|||
value={profileID ? profileID : inputValue}
|
||||
onClick={onInputClick}
|
||||
onChange={onTextInputChange}
|
||||
onKeyDown={onKeyDown}
|
||||
autoComplete="off"
|
||||
placeholder="None"
|
||||
isExpanded={isOpen}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue