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

Standalone labels #514

Merged
merged 2 commits into from
Sep 5, 2024
Merged

Standalone labels #514

merged 2 commits into from
Sep 5, 2024

Conversation

peteryates
Copy link
Member

This PR exposes GOVUKDesignSystemFormBuilder::Elements::Label directly via #govuk_label. It's intended to allow authors to place the label somewhere other than immediately above the input.

Its usage isn't covered by the design system so comes with the risk that the error message will still be rendered next to the input which will likely break layouts when used in confined spaces (i.e., table cells)

The regular label arguments will still work so authors can customise the label's:

  • size
  • wrapping tag
  • caption
  • visibility

Copy link

netlify bot commented Jul 21, 2024

Deploy Preview for govuk-form-builder ready!

Name Link
🔨 Latest commit 298d836
🔍 Latest deploy log https://app.netlify.com/sites/govuk-form-builder/deploys/66d4bf52cc599c00073136fc
😎 Deploy Preview https://deploy-preview-514--govuk-form-builder.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

This simply exposes GOVUKDesignSystemFormBuilder::Elements::Label via a
new `#govuk_label` method on the builder object. It is intended to be
used on occasions where the label isn't wanted immediately above the
input, such as in a table.

Fixes #480
This is quite an advanced use which will stretch the Design System to
the limit. HTML has long-supported placing labels far from the
corresponding input, even outside the form altogether. The risk here is
that error messages now will be placed by the input, which has a strong
likelihood of breaking layouts.

Still, I'm sure some people will find a use for this.

Fixes #477
subject { builder.send(*args, **kwargs) }

specify 'renders a label with the right custom text' do
expect(subject).to have_tag('label', text: custom_label_text, with: { class: 'govuk-label' })
Copy link
Collaborator

Choose a reason for hiding this comment

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

Worth adding a test for the for attribute too, given that this will be needed to link the label to the input?

Copy link
Member Author

Choose a reason for hiding this comment

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

Missed this, but yeah it is. Will add it.

Copy link
Collaborator

@frankieroberto frankieroberto left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@peteryates peteryates merged commit 4debc6e into main Sep 5, 2024
17 checks passed
@peteryates peteryates deleted the standalone-labels branch September 5, 2024 22:13
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.

2 participants