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

com.github.mvysny.kaributesting.v10.RadioButtons.kt Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
package com.github.mvysny.kaributesting.v10

import com.vaadin.flow.component.Component
import com.vaadin.flow.component.ItemLabelGenerator
import com.vaadin.flow.component.radiobutton.RadioButtonGroup
import com.vaadin.flow.component.select.Select
import com.vaadin.flow.data.renderer.ComponentRenderer

/**
 * Returns all item's captions.
 */
public fun  RadioButtonGroup.getItemLabels(): List {
    val labelGenerator = itemLabelGenerator
    return dataProvider._findAll().map { labelGenerator.apply(it) }
}

internal val  RadioButtonGroup.itemLabelGenerator: ItemLabelGenerator get() {
    val r = itemRenderer
    return ItemLabelGenerator { r._getPresentationValue(it).toString() }
}

/**
 * Retrieves a component produced by [RadioButtonGroup.itemRenderer]. Fails if the
 * renderer is not a [ComponentRenderer].
 * @param item the item
 * @throws IllegalStateException if the renderer is not [ComponentRenderer].
 */
public fun  RadioButtonGroup._getRenderedComponent(item: T): Component =
    itemRenderer.createComponent(item)

/**
 * Select an item in the radio button group by [label].
 *
 * Fails if the item is not found, or multiple items are found. Fails if the radio button group is not editable.
 */
public fun  RadioButtonGroup.selectByLabel(label: String) {
    selectByLabel(label, dataProvider, itemLabelGenerator)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy