Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(styles): Don't clip radio buttons #1261

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions packages/form-js-carbon-styles/src/carbon-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ const READONLY_STYLES = css`
}
}
&.fjs-checked .fjs-input[type='checkbox'],
.fjs-form-field-label.fjs-checked .fjs-input[type='checkbox'] {
&.fjs-checked .fjs-input[type='checkbox'] {
&:before {
border: 1px solid var(--cds-icon-disabled);
background: transparent;
Expand Down Expand Up @@ -418,8 +417,8 @@ const LABEL_DESCRIPTION_ERROR_STYLES = css`
margin-bottom: var(--cds-spacing-03);
}
.fjs-form-field.fjs-form-field-radio .fjs-form-field-label:not(:first-of-type),
.fjs-form-field.fjs-form-field-checklist .fjs-form-field-label:not(:first-of-type) {
.fjs-form-field.fjs-form-field-radio .fjs-inline-label,
.fjs-form-field.fjs-form-field-checklist .fjs-inline-label {
margin: 0;
margin-bottom: 0.1875rem;
}
Expand Down Expand Up @@ -515,7 +514,7 @@ const CHECKBOX_STYLES = css`
}
.fjs-form-field.fjs-checked .fjs-input[type='checkbox'],
.fjs-form-field .fjs-form-field-label.fjs-checked .fjs-input[type='checkbox'] {
.fjs-form-field .fjs-inline-label.fjs-checked .fjs-input[type='checkbox'] {
&:before {
border: none;
border-width: 1px;
Expand Down
11 changes: 5 additions & 6 deletions packages/form-js-carbon-styles/src/carbon-styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,7 @@
}
}

&.fjs-checked .fjs-input[type='checkbox'],
.fjs-form-field-label.fjs-checked .fjs-input[type='checkbox'] {
&.fjs-checked .fjs-input[type='checkbox'] {
&:before {
border: 1px solid var(--cds-icon-disabled);
background: transparent;
Expand Down Expand Up @@ -535,13 +534,13 @@
margin-bottom: var(--cds-spacing-03);
}

.fjs-form-field.fjs-form-field-radio .fjs-form-field-label:not(:first-of-type),
.fjs-form-field.fjs-form-field-checklist .fjs-form-field-label:not(:first-of-type) {
.fjs-form-field.fjs-form-field-radio .fjs-inline-label,
.fjs-form-field.fjs-form-field-checklist .fjs-inline-label {
margin: 0;
margin-bottom: 0.1875rem;
}

.fjs-form-field.fjs-form-field-radio .fjs-form-field-label:not(:first-of-type) {
.fjs-form-field.fjs-form-field-radio .fjs-inline-label {
min-height: #{rem(27)};
}

Expand Down Expand Up @@ -632,7 +631,7 @@
}

.fjs-form-field.fjs-checked .fjs-input[type='checkbox'],
.fjs-form-field .fjs-form-field-label.fjs-checked .fjs-input[type='checkbox'] {
.fjs-form-field .fjs-inline-label.fjs-checked .fjs-input[type='checkbox'] {
&:before {
border: none;
border-width: 1px;
Expand Down
5 changes: 5 additions & 0 deletions packages/form-js-viewer/assets/form-js-base.css
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@
opacity: 1;
}

.fjs-container .fjs-inline-label {
align-items: center;
display: flex;
}

.fjs-container .fjs-form-field-label {
display: flex;
align-items: center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function Checkbox(props) {

return (
<div class={classNames(formFieldClasses(type, { errors, disabled, readonly }), { 'fjs-checked': value })}>
<Label htmlFor={domId} label={label} required={required}>
<div class="fjs-inline-label">
<input
checked={value}
class="fjs-input"
Expand All @@ -41,7 +41,8 @@ export function Checkbox(props) {
aria-invalid={errors.length > 0}
aria-describedby={[descriptionId, errorMessageId].join(' ')}
/>
</Label>
<Label htmlFor={domId} label={label} required={required} />
</div>
<Description id={descriptionId} description={description} />
<Errors id={errorMessageId} errors={errors} />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,33 +68,32 @@ export function Checklist(props) {
<div class={classNames(formFieldClasses(type, { errors, disabled, readonly }))} ref={outerDivRef}>
<Label label={label} required={required} />
{loadState == LOAD_STATES.LOADED &&
options.map((o, index) => {
options.map((option, index) => {
const itemDomId = `${domId}-${index}`;
const isChecked = hasEqualValue(o.value, values);
const isChecked = hasEqualValue(option.value, values);

return (
<Label
htmlFor={itemDomId}
label={o.label}
class={classNames({
<div
className={classNames('fjs-inline-label', {
'fjs-checked': isChecked,
})}
required={false}>
key={option.value}>
<input
checked={isChecked}
class="fjs-input"
disabled={disabled}
readOnly={readonly}
id={itemDomId}
type="checkbox"
onClick={() => toggleCheckbox(o.value)}
onClick={() => toggleCheckbox(option.value)}
onBlur={onCheckboxBlur}
onFocus={onCheckboxFocus}
required={required}
aria-invalid={errors.length > 0}
aria-describedby={[descriptionId, errorMessageId].join(' ')}
/>
</Label>
<Label htmlFor={itemDomId} label={option.label} required={false} />
</div>
);
})}
<Description id={descriptionId} description={description} />
Expand Down
19 changes: 12 additions & 7 deletions packages/form-js-viewer/src/render/components/form-fields/Radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ export function Radio(props) {
const isChecked = isEqual(option.value, value);

return (
<Label
htmlFor={itemDomId}
key={index}
label={option.label}
class={classNames({ 'fjs-checked': isChecked })}
required={false}>
<div
className={classNames('fjs-inline-label', {
'fjs-checked': isChecked,
})}
key={option.value}>
<input
checked={isChecked}
class="fjs-input"
Expand All @@ -89,7 +88,13 @@ export function Radio(props) {
required={required}
aria-invalid={errors.length > 0}
/>
</Label>
<Label
htmlFor={itemDomId}
label={option.label}
class={classNames({ 'fjs-checked': isChecked })}
required={false}
/>
</div>
);
})}
<Description id={descriptionId} description={description} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ export function Taglist(props) {
{shouldDisplayDropdown && (
<DropdownList
values={filteredOptions}
getLabel={(o) => o.label}
onValueSelected={(o) => selectValue(o.value)}
getLabel={(option) => option.label}
onValueSelected={(option) => selectValue(option.value)}
emptyListMessage={hasOptionsLeft ? 'No results' : 'All values selected'}
listenerElement={inputRef.current}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ export function SearchableSelect(props) {
return options;
}

return options.filter((o) => o.label && o.value && o.label.toLowerCase().includes(filter.toLowerCase()));
return options.filter(
(option) => option.label && option.value && option.label.toLowerCase().includes(filter.toLowerCase()),
);
}, [filter, loadState, options, isFilterActive]);

const setValue = useCallback(
const pickOption = useCallback(
(option) => {
setFilter((option && option.label) || '');
props.onChange({ value: (option && option.value) || null });
Expand Down Expand Up @@ -159,7 +161,7 @@ export function SearchableSelect(props) {
<span
class="fjs-select-cross"
onMouseDown={(e) => {
setValue(null);
pickOption(null);
e.preventDefault();
}}>
<XMarkIcon />{' '}
Expand All @@ -173,9 +175,9 @@ export function SearchableSelect(props) {
{displayState.displayDropdown && (
<DropdownList
values={filteredOptions}
getLabel={(o) => o.label}
onValueSelected={(o) => {
setValue(o);
getLabel={(option) => option.label}
onValueSelected={(option) => {
pickOption(option);
setIsDropdownExpanded(false);
}}
listenerElement={searchbarRef.current}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function SimpleSelect(props) {

const valueLabel = useMemo(() => value && getLabelCorrelation(value), [value, getLabelCorrelation]);

const setValue = useCallback(
const pickOption = useCallback(
(option) => {
props.onChange({ value: (option && option.value) || null });
},
Expand Down Expand Up @@ -68,7 +68,7 @@ export function SimpleSelect(props) {
);

const initialFocusIndex = useMemo(
() => (value && findIndex(options, (o) => o.value === value)) || 0,
() => (value && findIndex(options, (option) => option.value === value)) || 0,
[options, value],
);

Expand Down Expand Up @@ -112,7 +112,7 @@ export function SimpleSelect(props) {
<span
class="fjs-select-cross"
onMouseDown={(e) => {
setValue(null);
pickOption(null);
e.stopPropagation();
}}>
<XMarkIcon />
Expand All @@ -124,10 +124,10 @@ export function SimpleSelect(props) {
{displayState.displayDropdown && (
<DropdownList
values={options}
getLabel={(o) => o.label}
getLabel={(option) => option.label}
initialFocusIndex={initialFocusIndex}
onValueSelected={(o) => {
setValue(o);
onValueSelected={(option) => {
pickOption(option);
setIsDropdownExpanded(false);
}}
listenerElement={selectRef.current}
Expand Down
Loading