Skip to content

Commit 0322220

Browse files
fixed textarea attribute autocorrect behavior, and...
- added missing `required` attribute to `textarea` macro - removed `nonce` attribute declaration in `script` macro, as it is a global attribute
1 parent 95c1ae6 commit 0322220

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

Sources/HTMLKit/HTMLKit.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,6 @@ public macro script<T: ExpressibleByStringLiteral>(
810810
fetchpriority: HTMLElementAttribute.Extra.fetchpriority? = nil,
811811
integrity: T? = nil,
812812
nomodule: Bool = false,
813-
nonce: T? = nil,
814813
referrerpolicy: HTMLElementAttribute.Extra.referrerpolicy? = nil,
815814
src: T? = nil,
816815
type: HTMLElementAttribute.Extra.scripttype? = nil,
@@ -947,8 +946,8 @@ public macro template<T: ExpressibleByStringLiteral>(
947946
public macro textarea<T: ExpressibleByStringLiteral>(
948947
attributes: [HTMLElementAttribute] = [],
949948

950-
autocomplete: [T]? = nil,
951-
autocorrect: T? = nil,
949+
autocomplete: [T] = [],
950+
autocorrect: HTMLElementAttribute.Extra.autocorrect? = nil,
952951
cols: Int? = nil,
953952
dirname: HTMLElementAttribute.Extra.dirname? = nil,
954953
disabled: Bool = false,
@@ -958,6 +957,7 @@ public macro textarea<T: ExpressibleByStringLiteral>(
958957
name: T? = nil,
959958
placeholder: T? = nil,
960959
readonly: Bool = false,
960+
required: Bool = false,
961961
rows: Int? = nil,
962962
wrap: HTMLElementAttribute.Extra.wrap? = nil,
963963
_ innerHTML: T...

Sources/HTMLKitUtilities/HTMLKitUtilities.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public enum HTMLElementAttribute {
126126
@available(*, deprecated, message: "General consensus considers this \"bad practice\" and you shouldn't mix your HTML and JavaScript. This will never be removed and remains deprecated to encourage use of other techniques. Learn more at https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#inline_event_handlers_—_dont_use_these.")
127127
case event(Extra.event, _ value: (any ExpressibleByStringLiteral)? = nil)
128128
}
129+
// MARK: Extra attributes
129130
public extension HTMLElementAttribute {
130131
enum Extra {
131132
}
@@ -134,32 +135,44 @@ public extension HTMLElementAttribute.Extra {
134135
typealias height = HTMLElementAttribute.CSSUnit
135136
typealias width = HTMLElementAttribute.CSSUnit
136137

138+
// MARK: as
137139
enum `as` : String {
138140
case audio, document, embed, fetch, font, image, object, script, style, track, video, worker
139141
}
140142

143+
// MARK: autocapitalize
141144
enum autocapitalize : String {
142145
case on, off
143146
case none
144147
case sentences, words, characters
145148
}
146149

150+
// MARK: autocomplete
147151
enum autocomplete : String {
148152
case off, on
149153
}
150154

155+
// MARK: autocorrect
156+
enum autocorrect : String {
157+
case off, on
158+
}
159+
160+
// MARK: blocking
151161
enum blocking : String {
152162
case render
153163
}
154164

165+
// MARK: buttontype
155166
enum buttontype : String {
156167
case submit, reset, button
157168
}
158169

170+
// MARK: capture
159171
enum capture : String {
160172
case user, environment
161173
}
162174

175+
// MARK: command
163176
enum command {
164177
case showModal
165178
case close

Tests/HTMLKitTests/ElementTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,18 +327,28 @@ extension ElementTests {
327327
}
328328

329329
// MARK: style
330+
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style
330331
@Test func style() {
331332
let string:StaticString = #style(blocking: .render)
332333
#expect(string == "<style blocking=\"render\"></style>")
333334
}
334335

336+
// MARK: td
337+
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td
338+
@Test func td() {
339+
let string:StaticString = #td(headers: ["puss", "in", "boots"])
340+
#expect(string == "<td headers=\"puss in boots\"></td>")
341+
}
342+
335343
// MARK: template
344+
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template
336345
@Test func template() {
337346
let string:StaticString = #template(shadowrootclonable: .false, shadowrootdelegatesfocus: false, shadowrootmode: .closed, shadowrootserializable: true)
338347
#expect(string == "<template shadowrootclonable=\"false\" shadowrootmode=\"closed\" shadowrootserializable></template>")
339348
}
340349

341350
// MARK: textarea
351+
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea
342352
@Test func textarea() {
343353
let string:StaticString = #textarea(autocomplete: ["email", "password"], dirname: .ltr, rows: 5, wrap: .soft)
344354
#expect(string == "<textarea autocomplete=\"email password\" dirname=\"ltr\" rows=\"5\" wrap=\"soft\"></textarea>")

0 commit comments

Comments
 (0)