Skip to content

Commit

Permalink
fix(input, input-number, input-text): Fix infinite loop crashing brow…
Browse files Browse the repository at this point in the history
…ser. #5882 (#5961)

**Related Issue:** #5882

## Summary

- Adds click handler to focus on internal inputs
- Focus handler only emits event
  • Loading branch information
driskull committed Dec 9, 2022
1 parent ae3c506 commit 190cfac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/components/input-number/input-number.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,14 @@ export class InputNumber
this.emitChangeIfUserModified();
};

private inputNumberFocusHandler = (event: FocusEvent): void => {
private clickHandler = (event: MouseEvent): void => {
const slottedActionEl = getSlotted(this.el, "action");
if (event.target !== slottedActionEl) {
this.setFocus();
}
};

private inputNumberFocusHandler = (): void => {
this.calciteInternalInputNumberFocus.emit();
};

Expand Down Expand Up @@ -923,7 +926,7 @@ export class InputNumber
);

return (
<Host onClick={this.inputNumberFocusHandler} onKeyDown={this.keyDownHandler}>
<Host onClick={this.clickHandler} onKeyDown={this.keyDownHandler}>
<div class={{ [CSS.inputWrapper]: true, [CSS_UTILITY.rtl]: dir === "rtl" }}>
{this.numberButtonType === "horizontal" && !this.readOnly
? numberButtonsHorizontalDown
Expand Down
7 changes: 5 additions & 2 deletions src/components/input-text/input-text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,14 @@ export class InputText
this.emitChangeIfUserModified();
};

private inputTextFocusHandler = (event: FocusEvent): void => {
private clickHandler = (event: MouseEvent): void => {
const slottedActionEl = getSlotted(this.el, "action");
if (event.target !== slottedActionEl) {
this.setFocus();
}
};

private inputTextFocusHandler = (): void => {
this.calciteInternalInputTextFocus.emit({
element: this.childEl,
value: this.value
Expand Down Expand Up @@ -587,7 +590,7 @@ export class InputText
);

return (
<Host onClick={this.inputTextFocusHandler} onKeyDown={this.keyDownHandler}>
<Host onClick={this.clickHandler} onKeyDown={this.keyDownHandler}>
<div class={{ [CSS.inputWrapper]: true, [CSS_UTILITY.rtl]: dir === "rtl" }}>
{this.prefixText ? prefixText : null}
<div class={CSS.wrapper}>
Expand Down
7 changes: 5 additions & 2 deletions src/components/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,14 @@ export class Input
this.emitChangeIfUserModified();
};

private inputFocusHandler = (event: FocusEvent): void => {
private clickHandler = (event: MouseEvent): void => {
const slottedActionEl = getSlotted(this.el, "action");
if (event.target !== slottedActionEl) {
this.setFocus();
}
};

private inputFocusHandler = (): void => {
this.calciteInternalInputFocus.emit();
};

Expand Down Expand Up @@ -1102,7 +1105,7 @@ export class Input
: null;

return (
<Host onClick={this.inputFocusHandler} onKeyDown={this.keyDownHandler}>
<Host onClick={this.clickHandler} onKeyDown={this.keyDownHandler}>
<div class={{ [CSS.inputWrapper]: true, [CSS_UTILITY.rtl]: dir === "rtl" }}>
{this.type === "number" && this.numberButtonType === "horizontal" && !this.readOnly
? numberButtonsHorizontalDown
Expand Down

0 comments on commit 190cfac

Please sign in to comment.