Skip to content

Commit

Permalink
Fix tag being erase when pressing backspace on single character bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nighto committed Nov 21, 2024
1 parent 9fc11a6 commit 91eac39
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export type InputFieldWithTagsProps = Omit<ComponentProps<'input'>, 'value'> & {
/** Callback to update the input value. Internally hooks to onChange */
onUpdate?: undefined | ((value: string) => void),

/** Callback to update the tags. Internally hooks to onKeyUp */
/** Callback to update the tags. Internally hooks to onKeyDown */
onUpdateTags?: undefined | ((tags: string[]) => void),
};
/**
Expand Down Expand Up @@ -69,10 +69,10 @@ export const InputFieldWithTags = (props: InputFieldWithTagsProps) => {
}
};

const onKeyUp = (e: React.KeyboardEvent<HTMLInputElement>) => {
// first handle supplied onKeyUp, if exists
if (inputProps.onKeyUp) {
inputProps.onKeyUp(e);
const onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
// first handle supplied onKeyDown, if exists
if (inputProps.onKeyDown) {
inputProps.onKeyDown(e);
}
// then return value to onUpdateTags
if (onUpdateTags && onUpdate) {
Expand Down Expand Up @@ -122,7 +122,7 @@ export const InputFieldWithTags = (props: InputFieldWithTagsProps) => {
form={formContext.formId}
className={cx(cl['bk-input-field-with-tags__control'], inputProps.className)}
onChange={onChange}
onKeyUp={onKeyUp}
onKeyDown={onKeyDown}
value={value}
/>
</div>
Expand Down

0 comments on commit 91eac39

Please sign in to comment.