git.iko.soy/typeable/elm-ui
on master help sign in
compensate for borders on textarea height: content
968f216Matthew Griffith
src/Element/Input.elm+30−9
@@ -691,7 +691,7 @@ textHelper textInput attrs textOptions =
691
691
692 TextArea ->
692 TextArea ->
693 let
693 let
694− { maybePadding, heightContent, maybeSpacing, adjustedAttributes } =
694+ { maybePadding, heightContent, maybeSpacing, adjustedAttributes, maybeBorder } =
695 attributes
695 attributes
696 |> List.foldr
696 |> List.foldr
697 (\attr found ->
697 (\attr found ->
@@ -710,11 +710,24 @@ textHelper textInput attrs textOptions =
710 _ ->
710 _ ->
711 found
711 found
712
712
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+
713 Internal.StyleClass _ (Internal.PaddingStyle _ t r b l) ->
724 Internal.StyleClass _ (Internal.PaddingStyle _ t r b l) ->
714 case found.maybePadding of
725 case found.maybePadding of
715 Nothing ->
726 Nothing ->
716 { found
727 { found
717 | maybePadding = Just (Padding t r b l)
728 | maybePadding = Just (Padding t r b l)
729+
730+ -- Skip storing padding because it's being customized later
718 , adjustedAttributes = found.adjustedAttributes
731 , adjustedAttributes = found.adjustedAttributes
719 }
732 }
720
733
@@ -737,6 +750,7 @@ textHelper textInput attrs textOptions =
737 )
750 )
738 { maybePadding = Nothing
751 { maybePadding = Nothing
739 , heightContent = Nothing
752 , heightContent = Nothing
753+ , maybeBorder = Nothing
740 , maybeSpacing = Nothing
754 , maybeSpacing = Nothing
741 , adjustedAttributes = []
755 , adjustedAttributes = []
742 }
756 }
@@ -766,7 +780,7 @@ textHelper textInput attrs textOptions =
766 Internal.NoAttribute
780 Internal.NoAttribute
767
781
768 Just True ->
782 Just True ->
769− textHeightContent textOptions.text spacing maybePadding
783+ textHeightContent textOptions.text spacing maybePadding maybeBorder
770
784
771 Just False ->
785 Just False ->
772 Internal.NoAttribute
786 Internal.NoAttribute
@@ -896,7 +910,7 @@ textHelper textInput attrs textOptions =
896 inputElement
910 inputElement
897
911
898
912
899−textHeightContent textValue spacing maybePadding =
913+textHeightContent textValue spacing maybePadding maybeBorder =
900 let
914 let
901 newlineCount =
915 newlineCount =
902 String.lines textValue
916 String.lines textValue
@@ -909,13 +923,20 @@ textHeightContent textValue spacing maybePadding =
909 x
923 x
910 )
924 )
911
925
912− heightValue count =
926+ topBottom (Padding t _ b _) =
913− case maybePadding of
927+ t + b
914− Nothing ->
928+
915− "calc(" ++ String.fromInt count ++ "em + " ++ String.fromInt ((count - 1) * spacing) ++ "px) !important"
929+ additionalSpacing =
930+ ((newlineCount - 1) * spacing)
931+ + Maybe.withDefault 0 (Maybe.map topBottom maybePadding)
932+ + Maybe.withDefault 0 (Maybe.map topBottom maybeBorder)
916
933
917− Just (Padding t r b l) ->
934+ heightValue count =
935+ "calc("
918− "calc(" ++ String.fromInt count ++ "em + " ++ String.fromInt ((t + b) + ((count - 1) * spacing)) ++ "px) !important"
936+ ++ String.fromInt count
937+ ++ "em + "
938+ ++ String.fromInt additionalSpacing
939+ ++ "px) !important"
919 in
940 in
920 Internal.StyleClass Flag.heightTextAreaContent
941 Internal.StyleClass Flag.heightTextAreaContent
921 (Internal.Single ("textarea-height-" ++ String.fromInt newlineCount)
942 (Internal.Single ("textarea-height-" ++ String.fromInt newlineCount)