Skip to content

Commit

Permalink
Updated SearchSelect, SingleSelect to the latest react features
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-podzigun committed Aug 19, 2019
1 parent 34d6247 commit f424f13
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package scommons.client.ui.select

import io.github.shogowada.scalajs.reactjs.React
import io.github.shogowada.scalajs.reactjs.VirtualDOM._
import io.github.shogowada.scalajs.reactjs.classes.ReactClass
import org.scalajs.dom
import scommons.react.UiComponent
import scommons.react._

import scala.concurrent.Future
import scala.concurrent.duration._
Expand All @@ -17,14 +14,14 @@ case class SearchSelectProps(selected: Option[SelectData],
isClearable: Boolean = false,
readOnly: Boolean = false)

object SearchSelect extends UiComponent[SearchSelectProps] {
object SearchSelect extends ClassComponent[SearchSelectProps] {

private case class SearchSelectState(isLoading: Boolean = false,
value: String = "",
handleId: Option[Int] = None,
options: List[SelectData] = Nil)

protected def create(): ReactClass = React.createClass[PropsType, SearchSelectState](
protected def create(): ReactClass = createClass[SearchSelectState](
getInitialState = { _ =>
SearchSelectState()
},
Expand Down
11 changes: 4 additions & 7 deletions ui/src/main/scala/scommons/client/ui/select/SingleSelect.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package scommons.client.ui.select

import io.github.shogowada.scalajs.reactjs.React
import io.github.shogowada.scalajs.reactjs.VirtualDOM._
import io.github.shogowada.scalajs.reactjs.classes.ReactClass
import scommons.client.ui.select.raw.NativeSelect._
import scommons.client.ui.select.raw.{ReactSelectAction, ReactSelectOption}
import scommons.react.UiComponent
import scommons.react._

import scala.scalajs.js

Expand All @@ -18,10 +15,10 @@ case class SingleSelectProps(selected: Option[SelectData],
onInputChange: Option[String => Unit] = None,
readOnly: Boolean = false)

object SingleSelect extends UiComponent[SingleSelectProps] {
object SingleSelect extends FunctionComponent[SingleSelectProps] {

protected def create(): ReactClass = React.createClass[PropsType, Unit] { self =>
val props = self.props.wrapped
protected def render(compProps: Props): ReactElement = {
val props = compProps.wrapped

<.ReactSelect(
^.className := "react-select-container",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package scommons.client.ui.select

import scommons.client.ui.select.raw._
import scommons.react.test.TestSpec
import scommons.react.test.dom.raw.ReactTestUtils._
import scommons.react.test.dom.util.TestDOMUtils
import scommons.react.test.raw.ShallowInstance
import scommons.react.test.util.ShallowRendererUtils

import scala.scalajs.js

class SingleSelectSpec extends TestSpec with ShallowRendererUtils with TestDOMUtils {
class SingleSelectSpec extends TestSpec
with ShallowRendererUtils
with TestDOMUtils {

it should "call onSelectChange(Some(data)) when onChange(option)" in {
//given
Expand Down Expand Up @@ -162,13 +163,10 @@ class SingleSelectSpec extends TestSpec with ShallowRendererUtils with TestDOMUt
val component = <(SingleSelect())(^.wrapped := props)()

//when
val result = renderIntoDocument(component)
domRender(component)

//then
val select = findRenderedComponentWithType(result, NativeReactSelect)

val container = findReactElement(select)
container.getAttribute("class") should include ("react-select-container")
val container = domContainer.querySelector(".react-select-container")

val control = container.firstElementChild
control.getAttribute("class") should include ("react-select__control")
Expand Down

0 comments on commit f424f13

Please sign in to comment.