Skip to content

Commit

Permalink
Add form legend required symbol (canonical#5214)
Browse files Browse the repository at this point in the history
* Add form legend required symbol

* Add is-required fieldset legend example

* Add fieldset required example

* Fix stylelint issues

* Use margin for spacing

* run prettier

* Apply code suggestions

* Update vanilla version

* Update to 4.16.0

* Update releases.yml with new class variant

---------

Co-authored-by: Julie Muzina <julie.muzina@canonical.com>
  • Loading branch information
britneywwc and jmuzina committed Aug 15, 2024
1 parent e9969d3 commit 154e858
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
url: /docs/patterns/cta-block#borderless
status: New
notes: We've introduced a new borderless variant of the CTA block component.
- component: Forms / Fieldset required
url: /docs/base/forms#fieldset
status: New
notes: We've introduced <code>is-required</code> to legend fieldset elements.
- version: 4.15.0
features:
- component: CTA Block
Expand Down
6 changes: 6 additions & 0 deletions scss/_base_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,11 @@
margin-right: 0;
padding: calc($spv--large - $input-border-thickness);
}

legend {
&.is-required::before {
content: '* ';
}
}
// stylelint-enable selector-max-type
}
6 changes: 6 additions & 0 deletions templates/docs/base/forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ You can use the `<fieldset>` element to divide the form into different logical s
View example of the base form fieldset
</a></div>

You can add `is-required` to `<legend>` to indicate required fields.

<div class="embedded-example"><a href="/docs/examples/patterns/forms/fieldset-required/" class="js-example">
View example of fieldset required fields
</a></div>

## Inline

By applying the class `.p-form--inline` and wrapping any form control in `.p-form__group` you can change the layout style of any form to be inline.
Expand Down
1 change: 1 addition & 0 deletions templates/docs/examples/patterns/forms/combined.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<section>{% include 'docs/examples/patterns/forms/checkbox-inline.html' %}</section>
<section>{% include 'docs/examples/patterns/forms/checkbox-validation.html' %}</section>
<section>{% include 'docs/examples/patterns/forms/dense.html' %}</section>
<section>{% include 'docs/examples/patterns/forms/fieldset-required.html' %}</section>
<section>{% include 'docs/examples/patterns/forms/form-help-text.html' %}</section>
<section>{% include 'docs/examples/patterns/forms/form-inline.html' %}</section>
<section>{% include 'docs/examples/patterns/forms/form-stacked.html' %}</section>
Expand Down
24 changes: 24 additions & 0 deletions templates/docs/examples/patterns/forms/fieldset-required.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends "_layouts/examples.html" %}
{% block title %}Forms / Fieldset required{% endblock %}

{% block standalone_css %}patterns_forms{% endblock %}

{% block content %}
<form>
<fieldset>
<legend class="is-required">Required input</legend>
<label class="p-radio">
<input type="radio" class="p-radio__input" name="radioPattern" aria-labelledby="radioExample1">
<span class="p-radio__label" id="radioExample1">.p-radio</span>
</label>
<label class="p-radio">
<input type="radio" class="p-radio__input" name="radioPattern" aria-labelledby="radioExample2">
<span class="p-radio__label" id="radioExample2">.p-radio</span>
</label>
<label class="p-radio">
<input type="radio" class="p-radio__input" name="radioPattern" aria-labelledby="radioExample3">
<span class="p-radio__label" id="radioExample3">.p-radio</span>
</label>
</fieldset>
</form>
{% endblock %}

0 comments on commit 154e858

Please sign in to comment.