Skip to content

Commit d323b88

Browse files
committed
feat: no options text readonly style
1 parent 6880071 commit d323b88

File tree

5 files changed

+30
-24
lines changed

5 files changed

+30
-24
lines changed

packages/pluggableWidgets/checkbox-radio-selection-web/src/CheckboxRadioSelection.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@
2828
<enumerationValue key="boolean">Boolean</enumerationValue>
2929
</enumerationValues>
3030
</property>
31-
<property key="controlType" type="enumeration" defaultValue="checkbox" required="true">
32-
<caption>Component</caption>
33-
<description />
34-
<enumerationValues>
35-
<enumerationValue key="checkbox">Checkbox</enumerationValue>
36-
<enumerationValue key="radio">Radio button</enumerationValue>
37-
</enumerationValues>
38-
</property>
3931

4032
<!-- ENUM & BOOLEAN-->
4133
<property key="attributeEnumeration" type="attribute" required="true" setLabel="true">
@@ -214,6 +206,14 @@
214206
<caption>Custom content</caption>
215207
<description />
216208
</property>
209+
<property key="controlType" type="enumeration" defaultValue="checkbox" required="true">
210+
<caption>Render type</caption>
211+
<description />
212+
<enumerationValues>
213+
<enumerationValue key="checkbox">Checkbox</enumerationValue>
214+
<enumerationValue key="radio">Radio button</enumerationValue>
215+
</enumerationValues>
216+
</property>
217217
<!-- END MISC PROPS -->
218218
</propertyGroup>
219219
<!-- END GENERAL -->

packages/pluggableWidgets/checkbox-radio-selection-web/src/components/RadioSelection/RadioSelection.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ChangeEvent, ReactElement, createElement, MouseEvent } from "react";
33
import { SelectionBaseProps, SingleSelector } from "../../helpers/types";
44
import { CaptionContent } from "../CaptionContent";
55
import { Placeholder } from "../Placeholder";
6+
import { If } from "@mendix/widget-plugin-component-kit/If";
67

78
export function RadioSelection({
89
selector,
@@ -48,6 +49,9 @@ export function RadioSelection({
4849
{options.map((optionId, index) => {
4950
const isSelected = currentId === optionId;
5051
const controlId = `${inputId}-${selector.controlType}-${index}`;
52+
if (isReadOnly && !isSelected && readOnlyStyle === "text") {
53+
return null;
54+
}
5155

5256
return (
5357
<div
@@ -56,16 +60,18 @@ export function RadioSelection({
5660
"widget-checkbox-radio-selection-item-selected": isSelected
5761
})}
5862
>
59-
<input
60-
type={selector.controlType}
61-
id={controlId}
62-
name={name}
63-
value={optionId}
64-
checked={isSelected}
65-
disabled={isReadOnly}
66-
tabIndex={tabIndex}
67-
onChange={handleChange}
68-
/>
63+
<If condition={!isReadOnly || readOnlyStyle !== "text"}>
64+
<input
65+
type={selector.controlType}
66+
id={controlId}
67+
name={name}
68+
value={optionId}
69+
checked={isSelected}
70+
disabled={isReadOnly}
71+
tabIndex={tabIndex}
72+
onChange={handleChange}
73+
/>
74+
</If>
6975
<CaptionContent
7076
onClick={(e: MouseEvent<HTMLDivElement>) => {
7177
e.preventDefault();

packages/pluggableWidgets/checkbox-radio-selection-web/src/helpers/EnumBool/EnumBooleanSingleSelector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class EnumBooleanSingleSelector implements SingleSelector {
5959
this.currentId = attr.value?.toString() ?? null;
6060
this.readOnly = attr.readOnly;
6161
this.validation = attr.validation;
62-
this.controlType = props.controlType;
62+
this.controlType = this.isBoolean ? props.controlType : "radio";
6363
}
6464

6565
setValue(value: string | null): void {

packages/pluggableWidgets/checkbox-radio-selection-web/src/ui/CheckboxRadioSelection.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
.radio-item {
99
display: none;
1010

11-
&.widget-checkbox-radio-selection-radio-item-selected {
11+
&.widget-checkbox-radio-selection-item-selected {
1212
display: block;
1313

1414
input {

packages/pluggableWidgets/checkbox-radio-selection-web/typings/CheckboxRadioSelectionProps.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ export type SourceEnum = "context" | "database" | "static";
1111

1212
export type OptionsSourceTypeEnum = "association" | "enumeration" | "boolean";
1313

14-
export type ControlTypeEnum = "checkbox" | "radio";
15-
1614
export type OptionsSourceAssociationCaptionTypeEnum = "attribute" | "expression";
1715

1816
export type OptionsSourceDatabaseCaptionTypeEnum = "attribute" | "expression";
@@ -25,6 +23,8 @@ export interface OptionsSourceStaticDataSourceType {
2523

2624
export type OptionsSourceCustomContentTypeEnum = "yes" | "no";
2725

26+
export type ControlTypeEnum = "checkbox" | "radio";
27+
2828
export type CustomEditabilityEnum = "default" | "never" | "conditionally";
2929

3030
export type ReadOnlyStyleEnum = "bordered" | "text";
@@ -41,7 +41,6 @@ export interface CheckboxRadioSelectionContainerProps {
4141
id: string;
4242
source: SourceEnum;
4343
optionsSourceType: OptionsSourceTypeEnum;
44-
controlType: ControlTypeEnum;
4544
attributeEnumeration: EditableValue<string>;
4645
attributeBoolean: EditableValue<boolean>;
4746
optionsSourceDatabaseDataSource?: ListValue;
@@ -62,6 +61,7 @@ export interface CheckboxRadioSelectionContainerProps {
6261
optionsSourceCustomContentType: OptionsSourceCustomContentTypeEnum;
6362
optionsSourceAssociationCustomContent?: ListWidgetValue;
6463
optionsSourceDatabaseCustomContent?: ListWidgetValue;
64+
controlType: ControlTypeEnum;
6565
customEditability: CustomEditabilityEnum;
6666
customEditabilityExpression: DynamicValue<boolean>;
6767
readOnlyStyle: ReadOnlyStyleEnum;
@@ -76,7 +76,6 @@ export interface CheckboxRadioSelectionPreviewProps {
7676
translate: (text: string) => string;
7777
source: SourceEnum;
7878
optionsSourceType: OptionsSourceTypeEnum;
79-
controlType: ControlTypeEnum;
8079
attributeEnumeration: string;
8180
attributeBoolean: string;
8281
optionsSourceDatabaseDataSource: {} | { caption: string } | { type: string } | null;
@@ -97,6 +96,7 @@ export interface CheckboxRadioSelectionPreviewProps {
9796
optionsSourceCustomContentType: OptionsSourceCustomContentTypeEnum;
9897
optionsSourceAssociationCustomContent: { widgetCount: number; renderer: ComponentType<{ children: ReactNode; caption?: string }> };
9998
optionsSourceDatabaseCustomContent: { widgetCount: number; renderer: ComponentType<{ children: ReactNode; caption?: string }> };
99+
controlType: ControlTypeEnum;
100100
customEditability: CustomEditabilityEnum;
101101
customEditabilityExpression: string;
102102
readOnlyStyle: ReadOnlyStyleEnum;

0 commit comments

Comments
 (0)