From 02029c03cf6db95c4550372f440bbf0557d4c8fb Mon Sep 17 00:00:00 2001 From: Tessa Kelly Date: Thu, 11 Nov 2021 13:58:25 -0800 Subject: [PATCH] Use the same view for Select as is used for TextInput --- src/Nri/Ui/Select/V8.elm | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/Nri/Ui/Select/V8.elm b/src/Nri/Ui/Select/V8.elm index 3817cdcf..708c23a2 100644 --- a/src/Nri/Ui/Select/V8.elm +++ b/src/Nri/Ui/Select/V8.elm @@ -4,7 +4,7 @@ module Nri.Ui.Select.V8 exposing , value , Attribute, defaultDisplayText , hiddenLabel, visibleLabel - , errorIf, errorMessage + , errorIf, errorMessage, guidance , custom, nriDescription, id, testId , containerCss, noMargin ) @@ -35,7 +35,7 @@ module Nri.Ui.Select.V8 exposing @docs Attribute, defaultDisplayText @docs hiddenLabel, visibleLabel -@docs errorIf, errorMessage +@docs errorIf, errorMessage, guidance @docs custom, nriDescription, id, testId @docs containerCss, noMargin @@ -46,7 +46,7 @@ import Css import Dict import Html.Styled.Attributes as Attributes exposing (css) import Html.Styled.Events as Events -import InputErrorAndGuidanceInternal exposing (ErrorState) +import InputErrorAndGuidanceInternal exposing (ErrorState, Guidance) import InputLabelInternal import Json.Decode exposing (Decoder) import Nri.Ui @@ -57,7 +57,6 @@ import Nri.Ui.Fonts.V1 as Fonts import Nri.Ui.Html.Attributes.V2 as Extra import Nri.Ui.Html.V3 exposing (viewJust) import Nri.Ui.InputStyles.V3 as InputStyles -import Nri.Ui.Message.V3 as Message import Nri.Ui.Util import SolidColor @@ -92,6 +91,13 @@ errorMessage = Attribute << InputErrorAndGuidanceInternal.setErrorMessage +{-| A guidance message shows below the input, unless an error message is showing instead. +-} +guidance : String -> Attribute value +guidance = + Attribute << InputErrorAndGuidanceInternal.setGuidance + + {-| Hides the visible label. (There will still be an invisible label for screen readers.) -} hiddenLabel : Attribute value @@ -193,6 +199,7 @@ type alias Config value = , valueToString : Maybe (value -> String) , defaultDisplayText : Maybe String , error : ErrorState + , guidance : Guidance , hideLabel : Bool , noMarginTop : Bool , containerCss : List Css.Style @@ -208,6 +215,7 @@ defaultConfig = , valueToString = Nothing , defaultDisplayText = Nothing , error = InputErrorAndGuidanceInternal.noError + , guidance = InputErrorAndGuidanceInternal.noGuidance , hideLabel = False , noMarginTop = False , containerCss = [] @@ -255,16 +263,7 @@ view label attributes = , defaultDisplayText = config.defaultDisplayText , isInError = isInError_ } - , viewJust - (\m -> - Message.view - [ Message.tiny - , Message.error - , Message.plaintext m - , Message.alertRole - ] - ) - (InputErrorAndGuidanceInternal.getErrorMessage config.error) + , InputErrorAndGuidanceInternal.view id_ config ]