Skip to content

Commit c620912

Browse files
committed
Fixed textareaField does not use label class specified in CSSFramework. Fixes #1437
1 parent 657cc94 commit c620912

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

IHP/View/CSSFramework.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ instance Default CSSFramework where
5757
styledFlashMessages cssFramework flashMessages = forEach flashMessages (styledFlashMessage cssFramework cssFramework)
5858

5959
styledFormField :: CSSFramework -> FormField -> Blaze.Html
60-
styledFormField cssFramework@CSSFramework {styledValidationResult, styledTextFormField, styledCheckboxFormField, styledSelectFormField} formField =
60+
styledFormField cssFramework@CSSFramework {styledValidationResult, styledTextFormField, styledCheckboxFormField, styledSelectFormField, styledTextareaFormField} formField =
6161
formGroup renderInner
6262
where
6363
renderInner = case get #fieldType formField of
@@ -493,7 +493,7 @@ tailwind = def
493493
>{fieldValue}</textarea>{validationResult}{helpText}
494494
|]
495495
where
496-
twLabelClass = "font-medium text-gray-700" <> " " <> labelClass
496+
twLabelClass = classes ["font-medium text-gray-700", (labelClass, not (null labelClass))]
497497
label = unless (disableLabel || null fieldLabel) [hsx|<label class={twLabelClass} for={fieldInputId}>{fieldLabel}</label>|]
498498
inputClass = (styledInputClass cssFramework formField, True)
499499
inputInvalidClass = styledInputInvalidClass cssFramework formField

Test/View/CSSFrameworkSpec.hs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,33 @@ tests = do
320320
it "should support show of BreadcrumbItem" do
321321
let breadcrumbItem = breadcrumbText "First item"
322322
show breadcrumbItem `shouldBe` "{ breadcrumbLabel = \"First item\", url = Nothing }"
323+
324+
describe "tailwind" do
325+
let cssFramework = tailwind
326+
327+
describe "textareaField" do
328+
let baseTextField = FormField
329+
{ fieldType = TextareaInput
330+
, fieldName = "body"
331+
, fieldLabel = "Body:"
332+
, fieldValue = "Hello\nWorld!"
333+
, fieldInputId = "body"
334+
, validatorResult = Nothing
335+
, additionalAttributes = []
336+
, fieldClass = ""
337+
, labelClass = ""
338+
, disabled = False
339+
, disableLabel = False
340+
, disableGroup = False
341+
, disableValidationResult = False
342+
, cssFramework = cssFramework
343+
, helpText = ""
344+
, placeholder = "Describe your issue"
345+
, required = False
346+
, autofocus = False
347+
}
348+
it "should render tailwind label classes" do
349+
styledFormField cssFramework cssFramework baseTextField `shouldRenderTo` "<div class=\"flex flex-col my-6 space-y-2\" id=\"form-group-body\"><label class=\"font-medium text-gray-700\" for=\"body\">Body:</label><textarea name=\"body\" placeholder=\"Describe your issue\" id=\"body\" class=\"focus:ring-blue-500 focus:border-blue-500 block w-full border-gray-300 rounded-md\">Hello\nWorld!</textarea></div>"
323350

324351

325352

0 commit comments

Comments
 (0)