The p-segmented-control can be integrated into a form in two ways: controlled or uncontrolled, depending on
your needs.
In the controlled approach, the p-segmented-control state is externally managed using the value property and
change event to keep it in sync with your application logic. This approach is ideal for complex forms or when using a
form library. Note that the component will still always update its internal value automatically when interacted with.
In the uncontrolled approach, the p-segmented-control automatically managing its own state and including its value
in form submissions through the ElementInternals
API. This is convenient for smaller forms or simple submissions.
Attention
The p-segmented-control lacks access to native ValidityState
properties and validationMessage, and it cannot display the native validation popover. This means
validation behavior and error display will need to be implemented separately if required.
For more details on form integration, refer to the Form section in the
developing documentation for your framework of choice, or find a full form integration
example in our examples repository.
Sometimes it's useful to render custom markup for label, description or message. Therefore, named slots can be
used. Make sure not to define the corresponding property on the host element when a named slot is used (because a
property definition is preferred over a named slot). For named slots only
phrasing content is
allowed.
In addition to the named slots label, description and message, there is also a label-after slot available. This
slot must be used to render content after the label which is not directly part of it (e.g. an external link or a
popover component).
Attention
If the p-segmented-control is in disabled/loading state
andlabel or label-after slots are used with focusable UI elements (e.g.
a or p-popover), the keyboard focus handling has to be managed manually to prevent focusing
disabled elements (e.g. add tabindex="-1" on those UI elements).
Some label with a link and a "label-after" slot.Some Popover content with a link.Some description with a link.Some error message with a link.Option 1Option 2Option 3Option 4Option 5
prev
next
Open in Stackblitz
<!doctype html>
<htmllang="en"class="auto"><head><title></title></head><bodyclass="bg-canvas"><p-segmented-controlstate="error"><spanslot="label"id="some-label-id"> Some label with a
<ahref="https://designsystem.porsche.com"class="underline"> link
</a> and a "label-after" slot.
</span><p-popoverslot="label-after"class="ms-static-xs"> Some Popover content with a
<ahref="https://designsystem.porsche.com"class="underline"> link
</a> .
</p-popover><spanslot="description"id="some-description-id"> Some description with a
<ahref="https://designsystem.porsche.com"class="underline"> link
</a> .
</span><spanslot="message"id="some-message-id"> Some error message with a
<ahref="https://designsystem.porsche.com"class="underline"> link
</a> .
</span><p-segmented-control-itemvalue="1"> Option 1
</p-segmented-control-item><p-segmented-control-itemvalue="2"> Option 2
</p-segmented-control-item><p-segmented-control-itemvalue="3"> Option 3
</p-segmented-control-item><p-segmented-control-itemvalue="4"> Option 4
</p-segmented-control-item><p-segmented-control-itemvalue="5"> Option 5
</p-segmented-control-item></p-segmented-control><script></script></body></html>