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

Implement fieldset component schema type definition #32

Merged
merged 1 commit into from
Nov 30, 2023
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
50 changes: 50 additions & 0 deletions src/formio/components/fieldset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {AnyComponentSchema, LayoutComponentSchema, OFExtensions} from '..';

type TranslatableKeys = 'label';

/**
* The fieldset component schema.
*
* Fieldsets are used to manage group fields together. They can improve accessibility
* by grouping related fields together.
*
* The `key` property has no effect on the submission data structure (it does not create
* a nesting level, the component is purely presentational).
*
* The label is displayed as the legend element, while the upstream component uses an
* explicit legend property for this purpose.
Comment on lines +14 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand this sentence:

  • The label is displayed as the legend element

legend == <legend>?

  • while the upstream component uses an explicit legend property for this purpose.

upstream = formio? What does explicit means here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. correct, this is about <legend>
  2. upstream = formio indeed, explicit as in component.legend exists and component.label is actually ignored

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok nice, I'd be interested to see how this will be implemented on the form builder as I've used <fieldset> with <legend> as well.

*
* @group Form.io components
* @category Concrete types
*/
export interface FieldsetComponentSchema
extends Omit<
LayoutComponentSchema<never>,
| 'placeholder'
| 'multiple'
| 'defaultValue'
| 'errors'
| 'description'
| 'hideLabel'
| 'disabled'
| 'validateOn'
> {
id: string;
key: string;
type: 'fieldset';
label: string;
/**
* Nested components inside the group/fieldset.
*/
components: AnyComponentSchema[];

// custom properties
/**
* Control whether the fieldset header/legend is displayed or not.
*
* @deprecated This should probably use the built-in `hideLabel` property instead,
* which requires a backend data migration and update to the SDK code.
*/
hideHeader: boolean;
openForms?: OFExtensions<TranslatableKeys>['openForms'];
}
1 change: 1 addition & 0 deletions src/formio/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export * from './address';
// Layout components
export * from './content';
export * from './columns';
export * from './fieldset';
4 changes: 3 additions & 1 deletion src/formio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
DateComponentSchema,
DateTimeComponentSchema,
EmailComponentSchema,
FieldsetComponentSchema,
FileComponentSchema,
IbanComponentSchema,
LicensePlateComponentSchema,
Expand Down Expand Up @@ -71,7 +72,8 @@ export type AnyComponentSchema =
| AddressComponentSchema
// layout
| ContentComponentSchema
| ColumnsComponentSchema;
| ColumnsComponentSchema
| FieldsetComponentSchema;

/**
* Convenience type alias for all supported concrete component schema types.
Expand Down
33 changes: 33 additions & 0 deletions test-d/formio/components/fieldset.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {expectAssignable} from 'tsd';

import {FieldsetComponentSchema} from '../../../lib';

// Minimal schema
expectAssignable<FieldsetComponentSchema>({
id: 'eqegfc',
type: 'fieldset',
key: 'fieldset',
label: 'Fieldset',
hideHeader: false,
components: [],
});

// Full schema
expectAssignable<FieldsetComponentSchema>({
id: 'eqegfc',
type: 'fieldset',
key: 'fieldset',
label: 'Fieldset',
tooltip: 'A tooltip for the group',
hideHeader: false,
hidden: true,
clearOnHide: true,
components: [
{
id: 'wien53il',
type: 'textfield',
key: 'nestedTextField',
label: 'Nested text field',
},
],
});