All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.raquo.laminar.receivers.FocusReceiver.scala Maven / Gradle / Ivy

The newest version!
package com.raquo.laminar.receivers

import com.raquo.airstream.core.Source.EventSource
import com.raquo.laminar.modifiers.Binder
import com.raquo.laminar.nodes.{ReactiveElement, ReactiveHtmlElement}

object FocusReceiver {

  def <--(isFocused: EventSource[Boolean]): Binder[ReactiveHtmlElement.Base] = {
    Binder { element =>
      ReactiveElement.bindFn(element, isFocused.toObservable) { shouldFocus =>
        if (shouldFocus) element.ref.focus() else element.ref.blur()
      }
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy