1.7.0 • Published 24 days ago

@spectrum-web-components/field-group v1.7.0

Weekly downloads
190
License
Apache-2.0
Repository
github
Last release
24 days ago

Overview

An <sp-field-group> element is used to layout a group of fields, usually <sp-checkbox> elements. It can be leveraged for vertical or horizontal organization of the fields that are supplied as its children.

Usage

See it on NPM! How big is this package in your project?

yarn add @spectrum-web-components/field-group

Import the side effectful registration of <sp-field-group> via:

import '@spectrum-web-components/field-group/sp-field-group.js';

When looking to leverage the FieldGroup base class as a type and/or for extension purposes, do so via:

import { FieldGroup } from '@spectrum-web-components/field-group';

Anatomy

<sp-field-group horizontal label="Choose from horizontally placed options">
    <sp-checkbox>Checkbox 1</sp-checkbox>
    <sp-checkbox>Checkbox 2</sp-checkbox>
    <sp-checkbox checked>Checkbox 3</sp-checkbox>
    <sp-checkbox>Checkbox 4</sp-checkbox>
    <sp-checkbox>Checkbox 5</sp-checkbox>
</sp-field-group>

Label

A field group must have a label in order to be accessible. A label can be provided either via the label attribute, like the previous example or with an <sp-field-label> element.

<sp-field-label for="horizontal">
    Choose from horizontally placed options
</sp-field-label>
<sp-field-group horizontal id="horizontal">
    <sp-checkbox>Checkbox 1</sp-checkbox>
    <sp-checkbox>Checkbox 2</sp-checkbox>
    <sp-checkbox checked>Checkbox 3</sp-checkbox>
    <sp-checkbox>Checkbox 4</sp-checkbox>
    <sp-checkbox>Checkbox 5</sp-checkbox>
</sp-field-group>

Help text

Help text can be accessibly associated with an <sp-field-group> element by using the help-text or negative-help-text slots. When using the negative-help-text slot, <sp-field-group> will self manage the presence of this content based on the value of the invalid property on your <sp-field-group> element. Content within the help-text slot will be show by default. When your <sp-field-group> should receive help text based on state outside of the complexity of invalid or not, manage the content addressed to the help-text from above to ensure that it displays the right messaging and possesses the right variant.

<sp-field-group horizontal id="self" label="What are your favorite fruits?">
    <sp-checkbox value="apple">Apple</sp-checkbox>
    <sp-checkbox
        value="not-a-fruit"
        onchange="javascript:this.parentElement.invalid = this.checked"
    >
        Lettuce
    </sp-checkbox>
    <sp-checkbox value="strawberry" checked>Strawberry</sp-checkbox>
    <sp-help-text slot="help-text">One of these is not a fruit.</sp-help-text>
    <sp-help-text slot="negative-help-text" icon>
        Choose actual fruit(s).
    </sp-help-text>
</sp-field-group>
<sp-field-label for="above">What are your favorite fruits?</sp-field-label>
<sp-field-group horizontal id="above">
    <sp-checkbox value="apple">Apple</sp-checkbox>
    <sp-checkbox
        value="not-a-fruit"
        onchange="
            const helpText = this.parentElement.querySelector(`[slot='help-text']`);
            helpText.icon = this.checked;
            helpText.textContent = this.checked ? 'Choose actual fruit(s).' : 'One of these is not a fruit.';
            helpText.variant = this.checked ? 'negative' : 'neutral';
        "
    >
        Lettuce
    </sp-checkbox>
    <sp-checkbox value="strawberry" checked>Strawberry</sp-checkbox>
    <sp-help-text slot="help-text">One of these is not a fruit.</sp-help-text>
</sp-field-group>

Options

Vertical

<sp-field-label for="vertical">
    Choose from vertically placed options
</sp-field-label>
<sp-field-group vertical id="vertical">
    <sp-checkbox>Checkbox 1</sp-checkbox>
    <sp-checkbox>Checkbox 2</sp-checkbox>
    <sp-checkbox>Checkbox 3</sp-checkbox>
    <sp-checkbox>Checkbox 4</sp-checkbox>
    <sp-checkbox checked>Checkbox 5</sp-checkbox>
</sp-field-group>

Accessibility

Include a label

Every field group should have a label. A field without a label is ambiguous and not accessible.

Include help text

The description in the help text is flexible and encompasses a range of guidance. Sometimes this guidance is about what to input, and sometime it’s about how to input. This includes information such as:

  • An overall description of the input field
  • Hints for what kind of information needs to be input
  • Specific formatting examples or requirements

Learn more about using help text.

Include negative help text

Write error messaging in a human-centered way by guiding a user and showing them a solution — don’t simply state what’s wrong and then leave them guessing as to how to resolve it. Ambiguous error messages can be frustrating and even shame-inducing for users. Also, keep in mind that something that a system may deem an error may not actually be perceived as an error to a user.

Learn more about writing error messages.

Do not us a placeholder as a replacement for a label or help-text

Putting instructions for how to complete an input, requirements, or any other essential information into placeholder text is not accessible. Once a value is entered, placeholder text is no longer viewable; if someone is using an automatic form filler, they will never get the information in the placeholder text.

Instead, use the help text description to convey requirements or to show any formatting examples that would help user comprehension. If there's placeholder text and help text at the same time, it becomes redundant and distracting, especially if they're communicating the same thing.

1.6.0

2 months ago

1.4.1-beta.0

3 months ago

1.5.0

3 months ago

1.3.0-beta.1

4 months ago

1.3.0-beta.2

4 months ago

1.3.0-beta.3

4 months ago

1.3.0-beta.4

4 months ago

1.3.0-beta.5

4 months ago

1.3.0-beta.6

4 months ago

1.3.0-beta.0

4 months ago

1.4.0

3 months ago

1.5.1-beta.0

3 months ago

1.1.0-beta.50

7 months ago

1.1.0-beta.51

7 months ago

1.1.0-beta.54

7 months ago

1.1.0-beta.55

7 months ago

1.1.0-beta.52

7 months ago

1.1.0-beta.53

7 months ago

1.4.0-beta.0

4 months ago

1.3.0

4 months ago

1.6.0-beta.0

3 months ago

1.2.0

4 months ago

1.1.0-beta.10

8 months ago

1.1.0-beta.11

8 months ago

1.1.0-beta.14

8 months ago

1.1.0-beta.15

8 months ago

1.1.0-beta.12

8 months ago

1.1.0-beta.13

8 months ago

1.1.0-beta.18

8 months ago

1.1.0-beta.19

8 months ago

1.3.0-testing.0

4 months ago

1.1.0-beta.16

8 months ago

1.1.0-beta.17

8 months ago

1.1.0-beta.9

8 months ago

1.1.0-beta.8

8 months ago

1.1.0-beta.7

8 months ago

1.1.0-beta.2

8 months ago

1.1.0-beta.21

8 months ago

1.1.0-beta.6

8 months ago

1.1.0-beta.22

8 months ago

1.1.0-beta.5

8 months ago

1.1.0-beta.4

8 months ago

1.1.0-beta.20

8 months ago

1.1.0-beta.3

8 months ago

1.1.0-beta.25

8 months ago

1.1.0-beta.26

8 months ago

1.1.0-beta.23

8 months ago

1.1.0-beta.24

8 months ago

1.1.0-beta.29

8 months ago

1.1.0-beta.27

8 months ago

1.1.0-beta.28

8 months ago

1.1.1

5 months ago

1.1.0

5 months ago

1.1.2

5 months ago

1.1.0-beta.32

8 months ago

1.1.0-beta.33

8 months ago

1.1.0-beta.30

8 months ago

1.1.0-beta.31

8 months ago

1.1.0-beta.36

8 months ago

1.1.0-beta.37

7 months ago

1.1.0-beta.34

8 months ago

1.1.0-beta.35

8 months ago

1.1.0-beta.38

7 months ago

1.1.0-beta.39

7 months ago

1.3.1-beta.0

4 months ago

1.1.0-beta.40

7 months ago

1.1.0-beta.43

7 months ago

1.1.0-beta.44

7 months ago

1.1.0-beta.41

7 months ago

1.1.0-beta.42

7 months ago

1.1.0-beta.47

7 months ago

1.1.0-beta.48

7 months ago

1.1.0-beta.45

7 months ago

1.1.0-beta.46

7 months ago

1.1.0-beta.49

7 months ago

1.2.0-beta.9

4 months ago

1.0.2

7 months ago

1.2.0-beta.8

4 months ago

1.0.1

8 months ago

1.0.3

7 months ago

1.2.0-beta.1

5 months ago

1.2.0-beta.0

5 months ago

1.2.0-beta.3

5 months ago

1.2.0-beta.2

5 months ago

1.2.0-beta.5

5 months ago

1.2.0-beta.4

5 months ago

1.2.0-beta.7

5 months ago

1.2.0-beta.6

5 months ago

1.7.0

24 days ago

1.5.0-beta.0

3 months ago

1.2.0-beta.16

4 months ago

1.2.0-beta.15

4 months ago

1.2.0-beta.18

4 months ago

1.2.0-beta.17

4 months ago

1.2.0-beta.12

4 months ago

1.2.0-beta.11

4 months ago

1.2.0-beta.14

4 months ago

1.2.0-beta.13

4 months ago

1.6.1-beta.0

2 months ago

1.2.0-beta.10

4 months ago

1.2.0-beta.19

4 months ago

1.0.0-rc.9

8 months ago

1.0.0-rc.7

8 months ago

1.0.0-rc.8

8 months ago

1.0.0-rc.5

8 months ago

1.0.0-rc.6

8 months ago

1.0.0-rc.10

8 months ago

1.0.0-rc.3

8 months ago

1.0.0-rc.4

8 months ago

1.0.0-rc.1

8 months ago

1.0.0-rc.2

8 months ago

0.50.0-beta.11

8 months ago

0.50.0-beta.12

8 months ago

0.50.0-beta.10

8 months ago

1.1.0-beta.1

8 months ago

1.1.0-beta.0

8 months ago

0.50.0-beta.9

8 months ago

0.50.0-beta.8

8 months ago

0.50.0-beta.7

8 months ago

0.50.0-beta.6

8 months ago

0.50.0-beta.5

8 months ago

0.50.0-beta.4

8 months ago

1.0.0

8 months ago

0.50.0-beta.3

8 months ago

0.50.0-beta.2

8 months ago

1.0.0-rc.0

9 months ago

0.50.0-beta.1

9 months ago

0.50.0-beta.0

9 months ago

0.49.0

9 months ago

0.49.0-beta.2

9 months ago

0.49.0-beta.1

9 months ago

0.48.1

9 months ago

0.48.0-beta.0

9 months ago

0.48.0-beta.1

9 months ago

0.48.0-beta.2

9 months ago

0.49.0-beta.0

9 months ago

0.43.0

1 year ago

0.48.0

10 months ago

0.44.0

12 months ago

0.45.0

11 months ago

0.46.0

11 months ago

0.42.5

1 year ago

0.47.1

10 months ago

0.47.2

10 months ago

0.47.0

11 months ago

0.42.4

1 year ago

0.42.3

1 year ago

0.42.2

1 year ago

0.42.1

1 year ago

0.42.0

1 year ago

0.41.2

1 year ago

0.41.1

1 year ago

0.41.0

1 year ago

0.40.5

1 year ago

0.40.4

1 year ago

0.40.3

1 year ago

0.40.2

2 years ago

0.40.1

2 years ago

0.36.0

2 years ago

0.40.0

2 years ago

0.35.1-rc.15

2 years ago

0.37.0

2 years ago

0.34.1-rc.0

2 years ago

0.35.1-rc.25

2 years ago

0.35.1-rc.26

2 years ago

0.35.1-rc.24

2 years ago

0.38.0

2 years ago

0.35.1-rc.34

2 years ago

0.34.0

2 years ago

0.35.1-rc.43

2 years ago

0.35.1-rc.41

2 years ago

0.39.1

2 years ago

0.39.0

2 years ago

0.35.0

2 years ago

0.39.4

2 years ago

0.39.3

2 years ago

0.39.2

2 years ago

0.31.1-react.21

2 years ago

0.32.0

2 years ago

0.31.1-react.3

2 years ago

0.31.1-react.2

2 years ago

0.33.2

2 years ago

0.33.0

2 years ago

0.30.0

2 years ago

0.31.0

2 years ago

0.8.6-overlay.9

2 years ago

0.8.5

2 years ago

0.8.4

2 years ago

0.8.7

2 years ago

0.8.6

2 years ago

0.8.6-overlay.8

2 years ago

0.8.8-overlay.10

2 years ago

0.8.8-overlay.11

2 years ago

0.8.8-overlay.12

2 years ago

0.8.8-overlay.13

2 years ago

0.8.8-overlay.14

2 years ago

0.8.8-overlay.15

2 years ago

0.8.8-overlay.17

2 years ago

0.8.8-overlay.18

2 years ago

0.8.6-overlay.22

2 years ago

0.8.3-react.75

2 years ago

0.8.3-react.50

2 years ago

0.8.3-react.49

2 years ago

0.8.3-react.48

2 years ago

0.8.3

2 years ago

0.8.3-react.32

2 years ago

0.7.6-react.54

3 years ago

0.8.1

2 years ago

0.8.0

3 years ago

0.8.2

2 years ago

0.7.2

3 years ago

0.7.4

3 years ago

0.7.3

3 years ago

0.7.5

3 years ago

0.7.1

3 years ago

0.7.0

3 years ago

0.5.10

3 years ago

0.5.11

3 years ago

0.6.0-devmode.0

3 years ago

0.5.12

3 years ago

0.5.12-devmode.0

3 years ago

0.5.12-devmode.7

3 years ago

0.5.13-devmode.0

3 years ago

0.6.0

3 years ago

0.5.8

3 years ago

0.5.7

3 years ago

0.5.9

3 years ago

0.5.6

3 years ago

0.5.4

3 years ago

0.5.5

3 years ago

0.5.2-express.41

3 years ago

0.5.3

3 years ago

0.5.2

3 years ago

0.5.3-express.12

3 years ago

0.5.4-express.9

3 years ago

0.5.0

4 years ago

0.5.1

4 years ago

0.4.1

4 years ago

0.4.1-lit-next.0

4 years ago

0.4.0

4 years ago

0.3.9

4 years ago

0.3.8

4 years ago

0.3.9-lit-next.0

4 years ago

0.3.8-alpha.69

4 years ago

0.3.8-alpha.40

4 years ago

0.3.8-alpha.1

4 years ago

0.3.7

4 years ago

0.3.7-alpha.59

4 years ago

0.3.7-alpha.1

4 years ago

0.3.6

4 years ago

0.3.6-alpha.74

4 years ago

0.3.6-alpha.73

4 years ago

0.3.6-alpha.72

4 years ago

0.3.6-alpha.61

4 years ago

0.3.6-alpha.27

4 years ago

0.3.6-alpha.0

4 years ago

0.3.5

4 years ago

0.3.4-alpha.26

4 years ago

0.3.4

4 years ago

0.3.4-alpha.23

4 years ago

0.3.4-alpha.21

4 years ago

0.3.4-beta.17

4 years ago

0.3.4-beta.15

4 years ago

0.3.4-beta.16

4 years ago

0.3.4-alpha.17

4 years ago

0.3.4-beta.10

4 years ago

0.3.4-beta.13

4 years ago

0.3.4-beta.14

4 years ago

0.3.4-beta.11

4 years ago

0.3.4-beta.12

4 years ago

0.3.4-alpha.11

4 years ago

0.3.4-alpha.12

4 years ago

0.3.4-alpha.9

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.3-alpha.33

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago

0.0.2-alpha.1403

4 years ago

0.2.0-alpha.1407

4 years ago

0.0.2-alpha.1394

4 years ago

0.0.2-alpha.1239

5 years ago

0.0.2-alpha.1238

5 years ago

0.0.2-alpha.1214

5 years ago