git.iko.soy/typeable/elm-ui
on master help sign in
compensate for borders on textarea height: content
commit968f21686cdf5984e85c2c743069c3cb5dbe4bda authorMatthew Griffith <mdg.griffith@gmail.com> dateFri 14 Sep 2018, 11:38 (8 years ago) parentd4175a3
1 file changed+30−9
src/Element/Input.elm+30−9
src/Element/Input.elm+30−9
@@ -691,7 +691,7 @@ textHelper textInput attrs textOptions =
691691
692692 TextArea ->
693693 let
694− { maybePadding, heightContent, maybeSpacing, adjustedAttributes } =
694+ { maybePadding, heightContent, maybeSpacing, adjustedAttributes, maybeBorder } =
695695 attributes
696696 |> List.foldr
697697 (\attr found ->
@@ -710,11 +710,24 @@ textHelper textInput attrs textOptions =
710710 _ ->
711711 found
712712
713+ Internal.StyleClass _ (Internal.BorderWidth _ t r b l) ->
714+ case found.maybeBorder of
715+ Nothing ->
716+ { found
717+ | maybeBorder = Just (Padding t r b l)
718+ , adjustedAttributes = attr :: found.adjustedAttributes
719+ }
720+
721+ _ ->
722+ found
723+
713724 Internal.StyleClass _ (Internal.PaddingStyle _ t r b l) ->
714725 case found.maybePadding of
715726 Nothing ->
716727 { found
717728 | maybePadding = Just (Padding t r b l)
729+
730+ -- Skip storing padding because it's being customized later
718731 , adjustedAttributes = found.adjustedAttributes
719732 }
720733
@@ -737,6 +750,7 @@ textHelper textInput attrs textOptions =
737750 )
738751 { maybePadding = Nothing
739752 , heightContent = Nothing
753+ , maybeBorder = Nothing
740754 , maybeSpacing = Nothing
741755 , adjustedAttributes = []
742756 }
@@ -766,7 +780,7 @@ textHelper textInput attrs textOptions =
766780 Internal.NoAttribute
767781
768782 Just True ->
769− textHeightContent textOptions.text spacing maybePadding
783+ textHeightContent textOptions.text spacing maybePadding maybeBorder
770784
771785 Just False ->
772786 Internal.NoAttribute
@@ -896,7 +910,7 @@ textHelper textInput attrs textOptions =
896910 inputElement
897911
898912
899−textHeightContent textValue spacing maybePadding =
913+textHeightContent textValue spacing maybePadding maybeBorder =
900914 let
901915 newlineCount =
902916 String.lines textValue
@@ -909,13 +923,20 @@ textHeightContent textValue spacing maybePadding =
909923 x
910924 )
911925
912− heightValue count =
913− case maybePadding of
914− Nothing ->
915− "calc(" ++ String.fromInt count ++ "em + " ++ String.fromInt ((count - 1) * spacing) ++ "px) !important"
926+ topBottom (Padding t _ b _) =
927+ t + b
928+
929+ additionalSpacing =
930+ ((newlineCount - 1) * spacing)
931+ + Maybe.withDefault 0 (Maybe.map topBottom maybePadding)
932+ + Maybe.withDefault 0 (Maybe.map topBottom maybeBorder)
916933
917− Just (Padding t r b l) ->
918− "calc(" ++ String.fromInt count ++ "em + " ++ String.fromInt ((t + b) + ((count - 1) * spacing)) ++ "px) !important"
934+ heightValue count =
935+ "calc("
936+ ++ String.fromInt count
937+ ++ "em + "
938+ ++ String.fromInt additionalSpacing
939+ ++ "px) !important"
919940 in
920941 Internal.StyleClass Flag.heightTextAreaContent
921942 (Internal.Single ("textarea-height-" ++ String.fromInt newlineCount)