Skip to content

Commit a30cf7d

Browse files
authored
fix(Checkbox): support checkbox value inside forms (#281)
1 parent 1d73574 commit a30cf7d

File tree

7 files changed

+17
-11
lines changed

7 files changed

+17
-11
lines changed

.changeset/friendly-snails-kick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cube-dev/ui-kit": patch
3+
---
4+
5+
Checkbox now has an abilility to have both a label and a text value inside forms.

src/components/forms/Checkbox/Checkbox.stories.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ const Template = (props) => (
2828
);
2929

3030
export const Default = Template.bind({});
31-
Default.args = {};
31+
Default.args = { children: 'Checkbox' };
3232

33-
export const WithoutLabel = Template.bind({});
34-
WithoutLabel.args = {
33+
export const WithoutValue = Template.bind({});
34+
WithoutValue.args = {
3535
label: '',
3636
};
3737

src/components/forms/Checkbox/Checkbox.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
castNullableIsSelected,
2727
WithNullableSelected,
2828
} from '../../../utils/react/nullableValue';
29+
import { Text } from '../../content/Text';
2930

3031
import { CheckboxGroup } from './CheckboxGroup';
3132
import { CheckboxGroupContext } from './context';
@@ -142,8 +143,6 @@ function Checkbox(
142143
...otherProps
143144
} = props;
144145

145-
label = label || children;
146-
147146
// Swap hooks depending on whether this checkbox is inside a CheckboxGroup.
148147
// This is a bit unorthodox. Typically, hooks cannot be called in a conditional,
149148
// but since the checkbox won't move in and out of a group, it should be safe.
@@ -223,6 +222,7 @@ function Checkbox(
223222
<CheckboxElement qa="Checkbox" mods={mods} styles={inputStyles}>
224223
{markIcon}
225224
</CheckboxElement>
225+
{children && <Text>{children}</Text>}
226226
</CheckboxWrapperElement>
227227
);
228228

@@ -233,6 +233,7 @@ function Checkbox(
233233
as: 'label',
234234
labelPosition,
235235
label,
236+
children,
236237
extra,
237238
styles,
238239
isRequired,
@@ -275,7 +276,7 @@ function Checkbox(
275276
}}
276277
{...filterBaseProps(labelProps)}
277278
>
278-
{label}
279+
{label || children}
279280
</Element>
280281
)}
281282
</CheckboxWrapperElement>

src/components/forms/Form/ComplexForm.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ const Template: StoryFn<typeof Form> = (args) => {
316316
name="checkbox"
317317
rules={[{ required: true, message: 'This field is required' }]}
318318
>
319-
<Checkbox label="Checkbox field" />
319+
<Checkbox label="Checkbox field">Checkbox value</Checkbox>
320320
</Field>
321321
<Field
322322
name="switch"

src/components/forms/NumberInput/NumberInput.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface CubeNumberInputProps
2828

2929
const StyledTextInputBase = tasty(TextInputBase, {
3030
wrapperStyles: {
31-
width: '13x',
31+
width: 'initial 13x 100%',
3232
},
3333
});
3434

@@ -70,7 +70,6 @@ function NumberInput(props: WithNullableValue<CubeNumberInputProps>, ref) {
7070
inputRef={inputRef}
7171
wrapperProps={groupProps}
7272
suffixPosition="after"
73-
textAlign="center"
7473
suffix={
7574
showStepper ? (
7675
<StepperContainer>

src/components/forms/RangeSlider/RangeInput.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ export function RangeInput(props: RangeInputProps) {
4343
{...otherProps}
4444
hideStepper
4545
size="small"
46-
inputStyles={{
46+
wrapperStyles={{
4747
width: inputWidth,
4848
}}
49+
textAlign="center"
4950
formatOptions={formatOptions}
5051
value={value}
5152
minValue={state.getThumbMinValue(index)}

src/components/forms/TextInput/TextInputBase.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const INPUT_STYLE_PROPS_LIST = [...BLOCK_STYLES, 'resize'];
131131
export const DEFAULT_INPUT_STYLES: Styles = {
132132
display: 'block',
133133
gridArea: 'input',
134-
width: 'initial 100% initial',
134+
width: 'initial 100% 100%',
135135
height: 'initial initial initial',
136136
color: 'inherit',
137137
fill: '#clear',

0 commit comments

Comments
 (0)