Skip to main content

MultipleChoiceFabric component

Component for rendering a list of selectable buttons.

📝 Signature​

MultipleChoiceFabric(props: {
styles: {
color: string;
outlineSize?: number;
roundness?: number;
scale?: number;
margin?: number;
};
buttons: IMultipleChoiceButton[];
alignment?: "vertical" | "equal" | "full" | "columns" | "horizontal";
required?: boolean;
disabled?: boolean;
readOnly?: boolean;
ariaDescribedBy?: string;
tabIndex?: number;
value?: string | Value;
autoSubmit?: boolean;
view?: "live" | "test" | "preview";
onChange?: (value: string) => void;
onFocus?: (e: FocusEvent) => void;
onBlur?: (e: FocusEvent) => void;
onAutoFocus?: (el: HTMLButtonElement | null) => void;
onSubmit?: () => void;
onCancel?: () => void;
}): JSX.Element

📇 Props​

NameTypeOptionalDescription
stylesobjectNoSpecifies the styles for the buttons. Supports the following styles:
- color: Base color for the buttons;
- outlineSize: Optional outline size in pixels for the buttons;
- roundness: Optional roundness in pixels for the buttons;
- scale: Optional scale factor for the buttons (defaults to 1);
- margin: Optional margin in pixels in between the buttons.
buttonsIMultipleChoiceButton[]NoSpecifies the buttons (see IMultipleChoiceButton).
alignment"vertical" | "equal" | "full" | "columns" | "horizontal"YesSpecifies the alignment of the button group (defaults to vertical).
requiredbooleanYesSpecifies if the component is required.
disabledbooleanYesSpecifies if the component is disabled.
readOnlybooleanYesSpecifies if the component is read-only.
ariaDescribedBystringYesSpecifies the aria-describedby identifier of the element that describes the component.
tabIndexnumberYesSpecifies the tabindex for the component.
valuestring | ValueYesSpecifies the value for the component. When a string is specified, this is the initial value for the input control. When a Value is supplied, this initial value is retrieved from the Value instance. Changes made in the input control are automatically reflected to the Value instance.
autoSubmitbooleanYesSpecifies if the component gets submitted when the user selects a button.
view"live" | "test" | "preview"YesSpecifies the view in which the component is shown.
onChange(value: string) => voidYesInvoked when the value of the component is changed.
onFocus(e: FocusEvent) => voidYesInvoked when the component gets focus.
onBlur(e: FocusEvent) => voidYesInvoked when the component loses focus.
onAutoFocus(el: HTMLButtonElement | null) => voidYesInvoked when the HTML element of the component is available for auto-focus.
onSubmit() => voidYesInvoked when the user presses the Shift + Enter key combination or the Tab key (this event is often used to go to the next input control in a form).
onCancel() => voidYesInvoked when the user presses the Shift + Tab key combination (this event is often used to go to the previous input control in a form).

↩ī¸ Return value​

Returns the JSX.Element for the component.

👩‍đŸ’ģ Example​

import { MultipleChoiceFabric } from "tripetto-runner-fabric/components/multiple-choice";

const MultipleChoiceFabricExample = () => (
<MultipleChoiceFabric
styles={{
color: "green"
}}
buttons={[
{
id: "1",
label: "Button 1",
onChange: (selected) => console.log(`Button 1 selected: ${selected}`)
},
{
id: "2",
label: "Button 2",
onChange: (selected) => console.log(`Button 2 selected: ${selected}`)
}
]}
/>
);

⛓ī¸ Interfaces​


🔗 IMultipleChoiceButton​

Describes the interface for a multiple choice button.

Type declaration​

interface IMultipleChoiceButton {
/* Identifier for the button. */
id: string;

/* Name for the button. */
name: string;

/* Value for the button. */
value?: string;

/* Description for the button. */
description?: string;

/* URL for the button. */
url?: string;

/* Target for the button URL. */
target?: "self" | "blank";

/* Specifies if the button is disabled. */
disabled?: boolean;

/* Specifies the button slot. */
slot: Slots.Boolean;

/* Tabindex for the button. */
tabIndex?: number;

/* Specifies the onChange function for the button. */
onChange?: (selected: boolean) => void;