Back to Fluentui

`@fluentui/react-input`: Styling implementation notes

packages/react-components/react-input/library/docs/Spec-styling.md

4.40.2-hotfix27.7 KB
Original Source

@fluentui/react-input: Styling implementation notes

Input has multiple size and appearance variants. These tables were created based on the design spec to assist with initial implementation and help ensure everything is handled.

General abbreviations used:

  • " = inherit from left
  • ^ = inherit from above
  • ^^ = inherit from 2 lines above

Sizes

Notes:

  • padding and gap values are from (theoretical) spacing.horizontal unless otherwise specified
  • interpretation:
    • "spacing between icon before and content"/"spacing between content and icon after 1" => "spacing within root"
    • "spacing between icon after 1 and icon after 2" => "spacing within contentBefore/After" because we're not going to have two icon slots
    • omitted "focus indicator" b/c that's handled elsewhere

For all field sizes

StyleApplicationAll
v-alignrootvertically centered
border radiusroot (unless underlined)medium
spacing within contentBefore/Aftern/a (add later if needed)xs

Varying by field size

StyleApplicationsmallmediumlarge
heightroot minHeight24px32px40px
left/right paddingrootsNudgemNudgem
left/right padding in contentinputxxsxxssNudge
content sizeroot, input (doesn't inherit)caption1 (base.200)body1 (base.300)base.400
"icon" sizecontentBefore/after > svg16Regular20Regular24Regular
spacing within rootroot display: flex, flex gapxxsxxssNudge

Appearance colors and strokes

Notes:

  • borders are thin (1px) unless otherwise noted
  • "in focus indicator" means the bottom border (applied to :after)
  • interpreting "compound brand stroke 1 pressed" as compoundBrandStrokePressed
  • mouse and keyboard focus styles are the same

TODO Open questions:

  • What color should the focus indicator be while animating? (pressed or non-pressed color)
  • For borderBottom pressed:
    • The designs for outline/underline show a thick bottom border in the pressed state as the focus indicator animates in, but this isn't included in the animation demoing the focus border (and I can't tell if Windows 11 uses it).
    • This wide border could be added on the root (while maintaining the blue focus border) using :focus-within:before + setting the bottom border color on :focus-within.

For all appearances

StyleApplicationAll
content colorinputneutralForeground1
content color disabled^neutralForegroundDisabled
placeholder colorinput ::placeholderneutralForeground4
placeholder color disabled^neutralForegroundDisabled
"icon" colorcontentBefore/AfterneutralForeground3
"icon" color disabled^neutralForegroundDisabled
background disabledroot, inputtransparentBackground
border disabledrootneutralStrokeDisabled
borderBottom focusedn/a (covered by focus indicator)
in focus indicatorroot :focus-within:afterthick compoundBrandStroke
in focus indicator pressedroot :afterthick ^Pressed
cursor disabledroot, inputnot-allowed

Varying per appearance

StyleApplicationoutlineunderlinefilledDarkerfilledLighter
shadowrootnone"shadow2"
backgroundroot, inputneutralBackground1transparentBackgroundneutralBackground3neutralBackground1
borderrootneutralStroke1nonetransparentStroke"
border hoverroot :hover^Hovern/a^Interactive"
border pressedroot :active^^Pressedn/a^"
border focusedroot :focus-withinn/a (neutralStroke1)n/a^"
borderBottomrootneutralStrokeAccessible"n/an/a
borderBottom hoverroot :hover^Hover"n/an/a
borderBottom pressedTODO (see ? above)thick ^^Pressed"n/an/a

In focus indicator

focus infocus out
apply toroot :focus-within:afterroot :after
transformscaleX 0-1scaleX 1-0
durationnormal (200ms)ultraFast (50ms)
easingdecelerateMidaccelerateMid

Bookends (deferred)

Bookend implementation has been deferred and will likely be handled in a separate component, but leaving these for reference.

Sizes

Stylesmallmediumlarge
v-alignvertically centered""
border radiusmedium""
left/right paddingsNudgesm
spacing withinxs""

Appearance

Stylefilledbrandtransparent
backgroundneutralBackground6brandBackgroundtransparentBackground
content (+icon)neutralForeground2neutralForegroundOnBrandneutralForeground2
bordertransparentStrokenonetransparentStroke
inner bordern/an/aneutralStroke3
  • Inner border ("border right") color is applied separately to before/after bookends.
  • Others are applied in obvious way to both bookends.
  • All borders are thin (1px).

Changes to default input appearance

  • Remove rounded corners from input
  • For filled inputs with shadow, change the shadow to also encompass the bookends