Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Reset custom power selector when blurred on empty #9508

Merged
merged 7 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

import { _t } from './languageHandler';

export function levelRoleMap(usersDefault: number) {
export function levelRoleMap(usersDefault: number): Record<number | "undefined", string> {
return {
undefined: _t('Default'),
0: _t('Restricted'),
Expand Down
8 changes: 6 additions & 2 deletions src/components/views/elements/PowerSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface IProps {
}

interface IState {
levelRoleMap: {};
levelRoleMap: Partial<Record<number | "undefined", string>>;
// List of power levels to show in the drop-down
options: number[];

Expand Down Expand Up @@ -125,7 +125,11 @@ export default class PowerSelector extends React.Component<IProps, IState> {
event.preventDefault();
event.stopPropagation();

this.props.onChange(this.state.customValue, this.props.powerLevelKey);
if (Number.isFinite(this.state.customValue)) {
this.props.onChange(this.state.customValue, this.props.powerLevelKey);
} else {
this.initStateFromProps(this.props); // reset, invalid input
}
};

private onCustomKeyDown = (event: React.KeyboardEvent<HTMLInputElement>): void => {
Expand Down