reactjseventsevent-handlingmaterial-uitextfield

Material UI TextField event for field leave


Is there an event for leaving the field or loosing focus in the Material UI TextField?

I need two events, one for entering and one for leaving the field. Entering the field can be handled by using onFocus, but is there also one for leaving, i.e. onFocusLost or onUnfocus? The following code segment show the current use, missing the event for loosing focus.

<TextField
    value={this.state.fieldFirstName}
    onChange={(e: any) => this.onChangeFieldFirstName(e.target.value)}
    onFocus={() => this.onFocusFieldFirstName()}
/>

Versions in use:


Solution

  • <TextField
    value={this.state.fieldFirstName}
    onChange={(e: any) => this.onChangeFieldFirstName(e.target.value)}
    onFocus={() => this.onFocusFieldFirstName()}
    onBlur={() => this.onBlurField()}/>
    

    Use onBlur event this will solve your problem