Skip to content

Commit

Permalink
fix(FormField): check focus event target to counter bubbling from por…
Browse files Browse the repository at this point in the history
  • Loading branch information
jfiala-cz committed Jul 29, 2024
1 parent aaf140d commit 5c821a9
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/js/components/FormField.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,29 @@ export default class FormField extends Component {
this.setState({focus: false});
}

_onClick () {
if (this._inputElement) {
this._inputElement.focus();
_onClick (evt) {
if (this._inputElement && this.containerRef) {
let node = evt.target;
let containerFound = false;
while (node && node.parentNode) {
if (node === document.body) {
break;
}
if (node === this.containerRef) {
containerFound = true;
break;
}
let nodeParent = null;
try {
nodeParent = node.parentNode;
} catch (e) {
// Nothing
}
node = nodeParent;
}
if (containerFound) {
this._inputElement.focus();
}
}
}

Expand Down Expand Up @@ -89,7 +109,7 @@ export default class FormField extends Component {
) : undefined;

return (
<div className={classes} {...props} onClick={this._onClick}>
<div className={classes} {...props} onClick={this._onClick} ref={ref => this.containerRef = ref}>
{fieldError}
{labelNode}
{fieldHelp}
Expand Down

0 comments on commit 5c821a9

Please sign in to comment.