Skip to content

Commit 7a84d5a

Browse files
committed
Option selected & disable condition
1 parent 9c16e39 commit 7a84d5a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Sources/SwiftHtml/Html/Tags/Option.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ public final class Option: Tag {
2121

2222
public extension Option {
2323
/// Specifies that an option should be disabled
24-
func disabled() -> Self {
25-
node.upsert(Attribute(key: "disabled"))
24+
func disabled(_ condition: Bool = true) -> Self {
25+
if condition {
26+
node.upsert(Attribute(key: "disabled"))
27+
}
2628
return self
2729
}
2830

@@ -33,8 +35,10 @@ public extension Option {
3335
}
3436

3537
/// Specifies that an option should be pre-selected when the page loads
36-
func selected() -> Self {
37-
node.upsert(Attribute(key: "selected"))
38+
func selected(_ condition: Bool = true) -> Self {
39+
if condition {
40+
node.upsert(Attribute(key: "selected"))
41+
}
3842
return self
3943
}
4044

0 commit comments

Comments
 (0)