Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
blur handler for form field tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
misteinb committed Aug 10, 2018
1 parent 5457cc6 commit 34a44c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## v3.0.2
### Fixed
- expose callback for clicking calendar icon in date picker. includes next visible state.
- blur handler for form field tooltip so it will close when focus leaves the field

## v3.0.1
### Fixed
Expand Down
16 changes: 15 additions & 1 deletion lib/components/Field/FormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class FormField extends React.PureComponent<FormFieldProps, FormFieldStat
constructor(props: FormFieldProps) {
super(props);
this.handleKeyDown = this.handleKeyDown.bind(this);
this.handleBlur = this.handleBlur.bind(this);
this._self = React.createRef();
this.state = {
tooltipVisible: false
Expand All @@ -100,6 +101,14 @@ export class FormField extends React.PureComponent<FormFieldProps, FormFieldStat
}
}

handleBlur(e: FocusEvent) {
if (!!e.relatedTarget && !this._self.current.contains(e.relatedTarget as HTMLElement)) {
this.setState({
tooltipVisible: false
});
}
}

render() {
const props = this.props;
const containerClass = css('input-container', {
Expand All @@ -113,7 +122,12 @@ export class FormField extends React.PureComponent<FormFieldProps, FormFieldStat
}

return (
<Attr.div methodRef={this._self} className={containerClass} attr={props.attr.fieldContainer}>
<Attr.div
methodRef={this._self}
className={containerClass}
attr={props.attr.fieldContainer}
onBlur={this.handleBlur}
>
{(!!props.label) && <FormLabel
name={props.name}
icon='info'
Expand Down

0 comments on commit 34a44c6

Please sign in to comment.