Anchor Design System
Form

Number3.0

Number description

Installation

npm i @tryg/ui-library

Usage

Individual only imports the desired component, and only needs to be included once within the application. Which is beneficial to keep the application size small.

Webcomponent
<script type="module">
  import { defineCustomElement } from '@tryg/ui-library/dist/components/anchor-number';
  defineCustomElement();
</script>
<anchor-number name="number-field" max-length="100" >Write a number</anchor-number>

Global only needs to be defined once in the application, but it will import all components even the ones that are not in use..

Webcomponent
<script type="module">
  import { defineCustomElements } from '@tryg/ui-library/dist/loader';
  defineCustomElements();
</script>
<anchor-number name="number-field" max-length="100" >Write a number</anchor-number>

Disabled

Webcomponent
<anchor-number name="number-field" disabled>Write a number</anchor-number>

Read Only

Webcomponent
<anchor-number name="number-field" readonly>Write a number</anchor-number>

Required

If you pass the required property to the input, the input will be required.

Webcomponent
<anchor-number name="number-field" required>Write a number</anchor-number>

Help text

You can add a helpful text to the input by passing the help-text property.

Webcomponent
<anchor-number name="number-field" help-text="This is a help text">Write a number</anchor-number>

With Error Message

You can combine the error-prop properties to show an invalid input.

Webcomponent
<anchor-number name="number-field" error-prop="This is a error message">Write a number</anchor-number>

Message Placements

You can change the position of the label by setting the messagePlacement property to inside, or below.

Webcomponent
<anchor-number error-prop="This is a error message">Hello</anchor-number>

Note

If the label is not passed, the messagePlacement property will be outside by default.

Controlled

You can use the value and onValueChange properties to control the input value.

Webcomponent
<script type="text/javascript">
  window.addEventListener("load", (event) => {
    document.querySelector('anchor-input').addEventListener('inputevent', function(data) {
      document.querySelector('#input-preview').innerHTML = data.detail.value
    })
  });
</script>
<anchor-input>Your number please</anchor-input>
<div id="input-preview"></div>

Accessibility

  • Built with a native <input> element.
  • Visual and ARIA labeling support.
    • aria-live attribute for the input field.
    • aria-describedby attribute for the input field.
    • aria-activedescendant attribute for the input field.
  • Change, clipboard, composition, selection, and input event support.
  • Required and invalid states exposed to assistive technology via ARIA.
    • aria-required attribute automatically set if required prop is set.
    • aria-invalid attribute automatically set if error-prop prop is set.
  • Support for description and error message help text linked to the input via ARIA.

API

anchor-number

Properties

PropertyAttributeDescriptionTypeDefault
disableddisabledDisable the number fieldbooleanfalse
errorProperror-propShow an error messagestring''
filledfilledShow a checkmark icon when the number field has been succesfully filledbooleanfalse
helpTexthelp-textShow a help textstring''
hideSpinButtonshide-spin-buttonsHide spin button when using type="number".booleanundefined
iconiconAdd an icon at the right side of the input field, by putting in the name of an Anchor icon"activity" | "airplay" | "alarm" | "alert-circle" | "alert-octagon" | "alert-triangle" | "align-center" | "align-justify" | "align-left" | "align-right" | "anchor" | "aperture" | "archive" | "arrow-down" | "arrow-down-circle" | "arrow-down-left" | "arrow-down-right" | "arrow-left" | "arrow-left-circle" | "arrow-right" | "arrow-right-circle" | "arrow-up" | "arrow-up-circle" | "arrow-up-left" | "arrow-up-right" | "at-sign" | "award" | "band-aid" | "bar-chart" | "bar-chart-2" | "basket" | "battery" | "battery-charging" | "bell" | "bell-off" | "bluetooth" | "bold" | "bonus-tryghedsgruppen" | "book" | "book-open" | "bookmark" | "box" | "briefcase" | "calculator" | "calendar" | "camera" | "camera-off" | "cast" | "check" | "check-circle" | "check-square" | "chevron-down" | "chevron-left" | "chevron-right" | "chevron-up" | "chevrons-down" | "chevrons-left" | "chevrons-right" | "chevrons-up" | "chrome" | "circle" | "clipboard" | "clock" | "cloud" | "cloud-drizzle" | "cloud-lightning" | "cloud-off" | "cloud-rain" | "cloud-snow" | "code" | "codepen" | "codesandbox" | "coffee" | "columns" | "command" | "company" | "compass" | "copy" | "corner-down-left" | "corner-down-right" | "corner-left-down" | "corner-left-up" | "corner-right-down" | "corner-right-up" | "corner-up-left" | "corner-up-right" | "cpu" | "credit-card" | "crop" | "crosshair" | "database" | "delete" | "disc" | "divide" | "divide-circle" | "divide-square" | "dollar-sign" | "download" | "download-cloud" | "dribbble" | "droplet" | "edit" | "edit-2" | "edit-3" | "external-link" | "eye" | "eye-off" | "facebook" | "fast-forward" | "feather" | "figma" | "file" | "file-minus" | "file-pdf" | "file-plus" | "file-text" | "film" | "filter" | "flag" | "folder" | "folder-minus" | "folder-plus" | "framer" | "frown" | "gift" | "git-branch" | "git-commit" | "git-merge" | "git-pull-request" | "github" | "gitlab" | "globe" | "grid" | "hard-drive" | "hash" | "headphones" | "heart" | "help-circle" | "hexagon" | "home" | "image" | "inbox" | "info" | "instagram" | "italic" | "key" | "layers" | "layout" | "life-buoy" | "link" | "link-2" | "linkedin" | "list" | "loader" | "lock" | "log-in" | "log-out" | "mail" | "map" | "map-pin" | "maximize" | "maximize-2" | "megaphone" | "meh" | "menu" | "message-circle" | "message-square" | "mic" | "mic-off" | "minimize" | "minimize-2" | "minus" | "minus-circle" | "minus-square" | "monitor" | "moon" | "more-horizontal" | "more-vertical" | "mouse-pointer" | "move" | "music" | "navigation" | "navigation-2" | "octagon" | "offer" | "package" | "paperclip" | "pause" | "pause-circle" | "pen-tool" | "percent" | "phone" | "phone-call" | "phone-forwarded" | "phone-incoming" | "phone-missed" | "phone-off" | "phone-outgoing" | "pie-chart" | "play" | "play-circle" | "plus" | "plus-circle" | "plus-square" | "pocket" | "power" | "printer" | "radio" | "refresh-ccw" | "refresh-cw" | "repeat" | "rewind" | "rotate-ccw" | "rotate-cw" | "rss" | "save" | "scissors" | "search" | "send" | "server" | "settings" | "share" | "share-2" | "shield" | "shield-off" | "shopping-bag" | "shopping-cart" | "shuffle" | "sidebar" | "skip-back" | "skip-forward" | "slack" | "slash" | "sliders" | "smartphone" | "smile" | "speaker" | "sprout" | "square" | "star" | "star-filled" | "stop-circle" | "storm" | "sun" | "sunrise" | "sunset" | "table" | "tablet" | "tag" | "target" | "terminal" | "thermometer" | "thumbs-down" | "thumbs-up" | "toggle-left" | "toggle-right" | "tool" | "trash" | "trash-2" | "trello" | "trending-down" | "trending-up" | "triangle" | "truck" | "trygfonden" | "tv" | "twitch" | "twitter" | "type" | "umbrella" | "underline" | "unlock" | "upload" | "upload-cloud" | "user" | "user-check" | "user-minus" | "user-plus" | "user-x" | "users" | "video" | "video-off" | "voicemail" | "volume" | "volume-1" | "volume-2" | "volume-x" | "watch" | "wifi" | "wifi-off" | "wind" | "x" | "x-circle" | "x-octagon" | "x-square" | "youtube" | "zap" | "zap-off" | "zoom-in" | "zoom-out"undefined
iconPlacementicon-placementShould the icon be inside or outside the input field"inside" | "outside"'inside'
labellabelShow the label (you can't currently disable the label)booleantrue
labelPlacementlabel-placementPlacement of the label"left" | "top"'top'
maxLengthmax-lengthSet a max width in characters for the number field.numberundefined
namenameThe name of the number fieldstring''
placeholderplaceholderPlaceholder text is shown until the user interacts with the number fieldstring''
readonlyreadonlySet the field to be read onlybooleanfalse
requiredrequiredMark the field as requiredbooleanfalse
sizesizeSet a fixed width in characters for the number field.numbernull
spinnersspinners"big" | "none" | "small"'none'
tooltipTexttooltip-textAdd an info icon with a tooltip to the right of the labelstring''
typetypeThe input type of the number fieldstring'text'
validityMissingValueTextvalidity-missing-value-textText to be displayed if when value is missing an native form validation is usedstringundefined
valuevalueThe value in the number field. Use this to set a valuenumber | stringnull
warningwarningShow a warning messagestring''

Events

EventDescriptionType
blureventEvent emitted when the user blurs the input fieldCustomEvent<any>
cleareventEvent emitted when the user clears the input fieldCustomEvent<any>
focuseventEvent emitted when the user is focusing the input fieldCustomEvent<any>
inputChangeEvent emitted when the input is changed. Only triggers when focus leaves the input.CustomEvent<EventDetail>
inputeventEvent emitted when the user is inputting something into the input fieldCustomEvent<EventDetail>

CSS Custom Properties

NameDescription
--number-input-border-colorSet the border color of the number input.
--number-input-border-color-disabledSet the border color of the number input when disabled.
--number-input-border-color-errorSet the border color of the number input for error states.
--number-input-border-color-focusSet the border color of the number input when focused.
--number-input-border-color-hoverSet the border color of the number input on hover.
--number-input-border-color-readonlySet the border color of the number input when readonly.
--number-input-border-color-warningSet the border color of the number input for warning states.
--number-input-border-widthSet the border width of the number input.
--number-input-max-widthSet the max width of the number input.
--number-input-padding-bottomSet the bottom padding of the number input.
--number-input-padding-leftSet the left padding of the number input.
--number-input-padding-rightSet the right padding of the number input.
--number-input-padding-topSet the top padding of the number input.
--number-input-widthSet the width of the number input.

Dependencies

Depends on

Graph


Built with StencilJS

Anchor versionStatusNotes
3.0Ready for ImplementationThis component is in sync with Figma.

On this page