Skip to content

Commit

Permalink
added required attribute (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
sliemeobn authored Jun 26, 2024
1 parent d792eae commit ca5d116
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Sources/Elementary/HtmlAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions Tests/ElementaryTests/AttributeRenderingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,11 @@ final class AttributeRenderingTests: XCTestCase {
#"<meta charset="UTF-8">"#
)
}

func testRendersRequired() {
HTMLAssertEqual(
input(.type(.text), .required),
#"<input type="text" required>"#
)
}
}

0 comments on commit ca5d116

Please sign in to comment.