Skip to main content

Input Wrapper Component

<primer-input-wrapper>

The primer-input-wrapper component provides consistent styling and structure for input fields. While it's used internally by card input components, you can also use it directly in custom layouts to create additional form fields that match the visual style of Primer's card inputs.

Usage

<primer-input-wrapper>
<primer-input-label slot="label">Discount Code</primer-input-label>
<div slot="input">
<primer-input id="discount-code"></primer-input>
</div>
</primer-input-wrapper>

Custom Layout Example

You can use primer-input-wrapper to add custom fields like discount codes alongside card inputs:

<primer-card-form>
<div slot="card-form-content">
<primer-input-card-holder-name></primer-input-card-holder-name>
<primer-input-card-number></primer-input-card-number>

<div style="display: flex; gap: 8px;">
<primer-input-card-expiry></primer-input-card-expiry>
<primer-input-cvv></primer-input-cvv>
</div>

<!-- Custom discount code field using primer-input-wrapper -->
<primer-input-wrapper>
<primer-input-label slot="label">Discount Code</primer-input-label>
<div slot="input" style="display: flex; gap: 8px; align-items: center;">
<primer-input id="discount-code" style="flex: 1;"></primer-input>
<button type="button" onclick="applyDiscount()">Apply</button>
</div>
</primer-input-wrapper>

<button type="submit">Pay Now</button>
</div>
</primer-card-form>

Slots

SlotDescription
labelSlot for the input label (use primer-input-label)
inputSlot for the input field content
help-textSlot for helper text or success messages

CSS Custom Properties

Spacing

PropertyDescription
--primer-space-xsmallGap between label and input field
--primer-space-mediumPadding inside the input container

Border

PropertyDescription
--primer-width-defaultDefault border width
--primer-width-focusBorder/outline width on focus
--primer-width-errorBorder/outline width in error state
--primer-radius-smallInput border radius
--primer-color-border-outlined-defaultDefault border color
--primer-color-border-outlined-hoverBorder color on hover
--primer-color-border-outlined-activeBorder color when active
--primer-color-border-outlined-focusBorder/outline color on focus
--primer-color-border-outlined-errorBorder/outline color in error state
--primer-color-border-outlined-disabledBorder color when disabled

Background

PropertyDescription
--primer-color-background-outlined-defaultDefault background color
--primer-color-background-outlined-hoverBackground color on hover
--primer-color-background-outlined-activeBackground color when active
--primer-color-background-outlined-errorBackground color in error state
--primer-color-background-outlined-disabledBackground color when disabled

Typography

PropertyDescription
--primer-typography-body-large-line-heightUsed to calculate input height

State Behavior

Default State

The input displays with default border and background colors, using --primer-width-default for border width.

Focus State

When focused, the input shows an outline using --primer-color-border-outlined-focus with width --primer-width-focus.

Hover State

On hover, border and background colors transition to their hover variants.

Error State

When the has-error attribute is present:

  • Border color changes to --primer-color-border-outlined-error
  • Background color changes to --primer-color-background-outlined-error
  • Border width increases to --primer-width-error
<primer-input-wrapper has-error>
<primer-input-label slot="label">Discount Code</primer-input-label>
<div slot="input">
<primer-input id="discount-code"></primer-input>
</div>
</primer-input-wrapper>

Disabled State

When disabled:

  • Background changes to --primer-color-background-outlined-disabled
  • Border changes to --primer-color-border-outlined-disabled
  • Cursor changes to not-allowed