diff --git a/packages/dnb-eufemia/src/components/toggle-button/ToggleButton.d.ts b/packages/dnb-eufemia/src/components/toggle-button/ToggleButton.d.ts
index edc074c5c7f..3ff3b53c62d 100644
--- a/packages/dnb-eufemia/src/components/toggle-button/ToggleButton.d.ts
+++ b/packages/dnb-eufemia/src/components/toggle-button/ToggleButton.d.ts
@@ -29,7 +29,7 @@ export interface ToggleButtonProps
/**
* (required) the text shown in the ToggleButton.
*/
- text?: string;
+ text?: React.ReactNode;
/**
* Use either the `label` property or provide a custom one.
*/
diff --git a/packages/dnb-eufemia/src/extensions/forms/Field/Selection/Selection.tsx b/packages/dnb-eufemia/src/extensions/forms/Field/Selection/Selection.tsx
index 2d0789ebece..5c9db20a452 100644
--- a/packages/dnb-eufemia/src/extensions/forms/Field/Selection/Selection.tsx
+++ b/packages/dnb-eufemia/src/extensions/forms/Field/Selection/Selection.tsx
@@ -1,6 +1,6 @@
import React, { useMemo, useContext, useCallback } from 'react'
import {
- Button,
+ ToggleButton,
Dropdown,
Radio,
HelpButton,
@@ -14,6 +14,7 @@ import Option from '../Option'
import { useDataValue } from '../../hooks'
import { FormError, FieldProps, FieldHelpProps } from '../../types'
import { pickSpacingProps } from '../../../../components/flex/utils'
+import ToggleButtonGroupContext from '../../../../components/toggle-button/ToggleButtonGroupContext'
interface IOption {
title: string | React.ReactNode
@@ -153,17 +154,21 @@ function Selection(props: Props) {
return (
- {options.map((option, i) => (
-
- ))}
+
+ {options.map((option, i) => (
+
+ ))}
+
)
diff --git a/packages/dnb-eufemia/src/extensions/forms/Field/Selection/__tests__/Selection.test.tsx b/packages/dnb-eufemia/src/extensions/forms/Field/Selection/__tests__/Selection.test.tsx
index 1e46246d947..7b38d6642ec 100644
--- a/packages/dnb-eufemia/src/extensions/forms/Field/Selection/__tests__/Selection.test.tsx
+++ b/packages/dnb-eufemia/src/extensions/forms/Field/Selection/__tests__/Selection.test.tsx
@@ -189,6 +189,57 @@ describe('Selection', () => {
expect(radioButtons[1]).not.toBeChecked()
})
})
+
+ describe('button', () => {
+ it('has no selected value by defualt', () => {
+ render(
+
+ Fooo
+ Baar
+
+ )
+
+ const buttons = document.querySelectorAll('button')
+ expect(buttons.length).toEqual(2)
+ expect(buttons[0].getAttribute('aria-pressed')).toBe('false')
+ expect(buttons[1].getAttribute('aria-pressed')).toBe('false')
+ })
+
+ it('renders selected option', () => {
+ render(
+
+ Fooo
+ Baar
+
+ )
+
+ const buttons = document.querySelectorAll('button')
+ expect(buttons.length).toEqual(2)
+ expect(buttons[0].getAttribute('aria-pressed')).toBe('false')
+ expect(buttons[1].getAttribute('aria-pressed')).toBe('true')
+ })
+
+ it('renders update selected option based on external value change', () => {
+ const { rerender } = render(
+
+ Fooo
+ Baar
+
+ )
+
+ rerender(
+
+ Fooo
+ Baar
+
+ )
+
+ const buttons = document.querySelectorAll('button')
+ expect(buttons.length).toEqual(2)
+ expect(buttons[0].getAttribute('aria-pressed')).toBe('true')
+ expect(buttons[1].getAttribute('aria-pressed')).toBe('false')
+ })
+ })
})
describe('event handlers', () => {