From 87df03b90339181ba2c88727a996b780d1338915 Mon Sep 17 00:00:00 2001
From: Simon Leeb <52261246+sliemeobn@users.noreply.github.com>
Date: Wed, 26 Jun 2024 09:04:59 +0200
Subject: [PATCH] added required attribute
---
Sources/Elementary/HtmlAttributes.swift | 15 +++++++++++++++
.../ElementaryTests/AttributeRenderingTests.swift | 7 +++++++
2 files changed, 22 insertions(+)
diff --git a/Sources/Elementary/HtmlAttributes.swift b/Sources/Elementary/HtmlAttributes.swift
index 8c2786d..8503602 100644
--- a/Sources/Elementary/HtmlAttributes.swift
+++ b/Sources/Elementary/HtmlAttributes.swift
@@ -210,6 +210,21 @@ public extension HTMLAttribute where Tag: HTMLTrait.Attributes.rel {
}
}
+// required attribute
+public extension HTMLTrait.Attributes {
+ protocol required {}
+}
+
+extension HTMLTag.input: HTMLTrait.Attributes.required {}
+extension HTMLTag.select: HTMLTrait.Attributes.required {}
+extension HTMLTag.textarea: HTMLTrait.Attributes.required {}
+
+public extension HTMLAttribute where Tag: HTMLTrait.Attributes.required {
+ static var required: Self {
+ HTMLAttribute(name: "required", value: nil)
+ }
+}
+
// form tag attributes
public extension HTMLAttribute where Tag == HTMLTag.form {
struct Method: Sendable, Equatable {
diff --git a/Tests/ElementaryTests/AttributeRenderingTests.swift b/Tests/ElementaryTests/AttributeRenderingTests.swift
index 94aff4b..0691dff 100644
--- a/Tests/ElementaryTests/AttributeRenderingTests.swift
+++ b/Tests/ElementaryTests/AttributeRenderingTests.swift
@@ -95,4 +95,11 @@ final class AttributeRenderingTests: XCTestCase {
#""#
)
}
+
+ func testRendersRequired() {
+ HTMLAssertEqual(
+ input(.type(.text), .required),
+ #""#
+ )
+ }
}