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

Add configuration to "Add another" #4575

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

davidtrussler
Copy link
Contributor

@davidtrussler davidtrussler commented Jan 20, 2025

What

Publishing Components Issue #4564

This adds some configuration to the "Add another" component so that authors can choose how the component displays by default when it is rendered on a page and no content is provided to it.

Why

The current default behaviour of the "Add another" component when it loads is to:

  • display empty form fields where no content is provided
  • not display a “Delete” button where a single instance of content is provided

There is a need to customise this behaviour for these scenarios when it is implemented on the Mainstream publisher app so that:

  • no empty fields are displayed where no content is provided
  • a "Delete" button is displayed where a single instance of content is provided

Visual Changes

The screenshots below show the component implemented on Mainstream Publisher as it currently displays and how it is displayed with these changes.

Before After
On load Screenshot 2025-01-24 at 09 59 50 Screenshot 2025-01-24 at 09 51 18
"Add another link" clicked Screenshot 2025-01-24 at 09 51 09

@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4575 January 20, 2025 16:51 Inactive
@davidtrussler davidtrussler force-pushed the 4564_Add-another-Configure-delete branch from f172a68 to 865981f Compare January 20, 2025 17:15
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4575 January 20, 2025 17:15 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4575 January 22, 2025 11:37 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4575 January 22, 2025 11:59 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4575 January 22, 2025 15:01 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4575 January 23, 2025 14:55 Inactive
@davidtrussler davidtrussler force-pushed the 4564_Add-another-Configure-delete branch from b78db53 to 547f2d8 Compare January 23, 2025 15:10
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4575 January 23, 2025 15:10 Inactive
@davidtrussler davidtrussler force-pushed the 4564_Add-another-Configure-delete branch from 547f2d8 to b9bfd0c Compare January 23, 2025 15:13
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4575 January 23, 2025 15:13 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4575 January 23, 2025 15:40 Inactive
@davidtrussler davidtrussler force-pushed the 4564_Add-another-Configure-delete branch from 27b3638 to d1b963a Compare January 23, 2025 16:08
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4575 January 23, 2025 16:08 Inactive
@davidtrussler davidtrussler force-pushed the 4564_Add-another-Configure-delete branch from d1b963a to e2013b6 Compare January 24, 2025 10:10
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4575 January 24, 2025 10:11 Inactive
@davidtrussler davidtrussler changed the title 4564 add another configure delete Add configuration to "Add another" Jan 24, 2025
@davidtrussler davidtrussler force-pushed the 4564_Add-another-Configure-delete branch from e2013b6 to 8f7893b Compare January 24, 2025 10:16
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4575 January 24, 2025 10:17 Inactive
@davidtrussler davidtrussler marked this pull request as ready for review January 24, 2025 10:24
Copy link
Contributor

@AshGDS AshGDS left a comment

Choose a reason for hiding this comment

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

LGTM, just had a couple questions 👍

<%= item[:destroy_checkbox] %>
</div>
<%= item[:fields] %>
<div data-module="add-another" class="gem-c-add-another" data-add-button-text="<%= add_button_text %>" data-fieldset-legend="<%= fieldset_legend %>" data-empty-fields="<%= empty_fields %>">
Copy link
Contributor

Choose a reason for hiding this comment

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

I think at this point it may be better to use the built in Rails tag.div syntax for adding data attributes e.g. <%= tag.div class: "classes", data: { fieldset_legend: "etc" } do %>

render_component({ items: default_items, empty_fields: true })

assert_select "div[data-module='add-another'][data-empty-fields='true']"
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the behaviour need to be tested e.g. it renders the empty state correctly?

Copy link
Contributor Author

@davidtrussler davidtrussler Jan 27, 2025

Choose a reason for hiding this comment

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

Good point: I've updated these tests a bit to duplicate and change them for the "Default" and "Start empty" options, which is probably the clearest way to present what it being tested.

@davidtrussler davidtrussler force-pushed the 4564_Add-another-Configure-delete branch from 8f7893b to dba9a8c Compare January 27, 2025 12:21
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4575 January 27, 2025 12:22 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4575 January 27, 2025 12:36 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4575 January 27, 2025 14:24 Inactive
@davidtrussler davidtrussler force-pushed the 4564_Add-another-Configure-delete branch from 321a551 to 09a891c Compare January 27, 2025 14:29
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4575 January 27, 2025 14:30 Inactive
@davidtrussler
Copy link
Contributor Author

LGTM, just had a couple questions 👍

Thanks @AshGDS - I've made a couple of updates in resonse to your queries if you'd be able to hae another quick look:

  • use the tag.div syntax
  • update the RSpec test to split it into "Default" and "Start empty" scenarios. That seemed to be the clearest way to express the difference in what is being tested in terms of the expected output.

module: "add-another",
"add-button-text": add_button_text,
"fieldset-legend": fieldset_legend,
"empty-fields": empty_fields
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can forgo using strings as Ruby would convert underscores to hyphens (e.g. add_button_text would become data-add-button-text, but this isn't a massive issue of course so feel free to leave it!

- Add new "start_empty" option to component doc
- Hidden class on "Delete" button added conditionaly on `empty-fields` data attribute
- Add `empty-fields` data-attribute to view
- Update JS test
- Update RSpec test
- Update CHANGELOG
@davidtrussler davidtrussler force-pushed the 4564_Add-another-Configure-delete branch from 09a891c to 95f291a Compare January 28, 2025 10:41
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4575 January 28, 2025 10:41 Inactive
@davidtrussler davidtrussler merged commit 3fc872a into main Jan 28, 2025
11 of 12 checks passed
@davidtrussler davidtrussler deleted the 4564_Add-another-Configure-delete branch January 28, 2025 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configure how the "Add another" component displays default form fields and "Delete" buttons
3 participants