Skip to content

Commit

Permalink
feat(TMC-25993): change default UIForm collapsible panel title (#5426)
Browse files Browse the repository at this point in the history
* feat(TMC-25993): change default UIForm collapsible panel title

* fix test

* fix test
  • Loading branch information
Gbacc authored Oct 16, 2024
1 parent 7665092 commit 3894e01
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/shiny-mirrors-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@talend/react-forms': minor
---

feat: Better handle collapsible fieldset title for UIForm definitions by using schema title by default
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ function getDrillKey(key) {
}

export function defaultTitle(formData, schema, options) {
if (schema.title) {
return schema.title;
}

const title = (schema.items || []).reduce((acc, item) => {
let value;
if (item.key) {
Expand Down Expand Up @@ -66,7 +70,7 @@ export function defaultTitle(formData, schema, options) {
return schema.options.emptyTitleFallback;
}

return schema.title;
return '';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function customTitle(value, schema) {
}

const schema = {
title: 'Basic',
description: 'This is description',
items: [
{
Expand Down Expand Up @@ -68,7 +67,10 @@ const defaultTitleMockData = {

const props = {
id: 'my-fieldset',
schema,
schema: {
...schema,
title: 'Basic',
},
value,
onChange: jest.fn(),
};
Expand All @@ -91,7 +93,7 @@ describe('CollapsibleFieldset', () => {
<CollapsibleFieldset {...props} value={{ ...value, isClosed: true }} />
</WidgetContext.Provider>,
);
expect(screen.getByText('Jimmy, Somsanith')).toBeInTheDocument();
expect(screen.getByText('Basic')).toBeInTheDocument();
expect(screen.getByRole('button')).toHaveAttribute('aria-expanded', 'false');
});
it('should render a custom title', () => {
Expand Down Expand Up @@ -182,11 +184,11 @@ describe('CollapsibleFieldset', () => {
});

describe('defaultTitle', () => {
it('should return schema.title by default if no emptyTitleFallback has been provided in options', () => {
it('should return schema.title by default', () => {
// given not used in an array you have the schema.title
expect(defaultTitle({}, { title: 'Comment' })).toBe('Comment');
// given no value, you have the schema.title
expect(defaultTitle({}, schema)).toBe(schema.title);
expect(defaultTitle({}, schema)).toBe('');
});

it('should return if emptyTitleFallback has been provided and computed title is empty', () => {
Expand Down Expand Up @@ -218,7 +220,6 @@ describe('defaultTitle', () => {
});
it('should support recursive call on deeper objects', () => {
const complexSchema = {
title: 'Basic',
items: [
{
key: ['type'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ exports[`CollapsibleFieldset should render 1`] = `
<span
class="theme-headerTitle"
>
Jimmy, Somsanith
Basic
</span>
</button>
<div
Expand Down

0 comments on commit 3894e01

Please sign in to comment.