Skip to content

Commit 231bde3

Browse files
committed
Fix: Move href, src, and formaction from reflected attributes to regular attributes
The mapping between props and attributes for those keys is not exactly an identity, e.g. if the provided URL is a relative one like , reading the attribute's value will return the same relative URL, but reading the prop will return a computed absolute URL that includes the domain name.
1 parent 6900584 commit 231bde3

File tree

4 files changed

+104
-98
lines changed

4 files changed

+104
-98
lines changed

js/src/test/scala/com/thirdparty/defs/attrs/HtmlAttrs.scala

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ trait HtmlAttrs {
5858
lazy val dropZone: HtmlAttr[String] = stringHtmlAttr("dropzone")
5959

6060

61+
/**
62+
* The `formaction` attribute provides the URL that will process the input control
63+
* when the form is submitted and overrides the default `action` attribute of the
64+
* `form` element. This should be used only with `input` elements of `type`
65+
* submit or image.
66+
*
67+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#formaction
68+
*/
69+
lazy val formAction: HtmlAttr[String] = stringHtmlAttr("formaction")
70+
71+
6172
/** The form attribute specifies an ID of the form an `<input>` element belongs to. */
6273
lazy val formId: HtmlAttr[String] = stringHtmlAttr("form")
6374

@@ -71,6 +82,20 @@ trait HtmlAttrs {
7182
lazy val heightAttr: HtmlAttr[Int] = intHtmlAttr("height")
7283

7384

85+
/**
86+
* This is the single required attribute for anchors defining a hypertext
87+
* source link. It indicates the link target, either a URL or a URL fragment.
88+
* A URL fragment is a name preceded by a hash mark (#), which specifies an
89+
* internal target location (an ID) within the current document. URLs are not
90+
* restricted to Web (HTTP)-based documents. URLs might use any protocol
91+
* supported by the browser. For example, file, ftp, and mailto work in most
92+
* user agents.
93+
*
94+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-href
95+
*/
96+
lazy val href: HtmlAttr[String] = stringHtmlAttr("href")
97+
98+
7499
/**
75100
* Identifies a list of pre-defined options to suggest to the user. The value must be
76101
* the id of a [[FormTags.dataList]] element in
@@ -99,6 +124,17 @@ trait HtmlAttrs {
99124
lazy val minAttr: HtmlAttr[String] = stringHtmlAttr("min")
100125

101126

127+
/**
128+
* Specifies the URL of an image for `<img>` tag, for `type="image"` input buttons,
129+
* or the URL of some other network resources like `<iframe>`.
130+
*
131+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-src
132+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#src
133+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-src
134+
*/
135+
lazy val src: HtmlAttr[String] = stringHtmlAttr("src")
136+
137+
102138
/**
103139
* The step attribute specifies the numeric intervals for an `<input>` element
104140
* that should be considered legal for the input. For example, if step is 2

js/src/test/scala/com/thirdparty/defs/props/Props.scala

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -283,17 +283,6 @@ trait Props {
283283
lazy val forId: Prop[String, String] = stringProp("htmlFor")
284284

285285

286-
/**
287-
* The `formaction` attribute provides the URL that will process the input control
288-
* when the form is submitted and overrides the default `action` attribute of the
289-
* `form` element. This should be used only with `input` elements of `type`
290-
* submit or image.
291-
*
292-
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#formaction
293-
*/
294-
lazy val formAction: Prop[String, String] = stringProp("formAction")
295-
296-
297286
/**
298287
* The `formenctype` attribute provides the encoding type of the form when it is
299288
* submitted (for forms with a method of "POST") and overrides the default
@@ -363,20 +352,6 @@ trait Props {
363352
lazy val high: Prop[Double, Double] = doubleProp("high")
364353

365354

366-
/**
367-
* This is the single required attribute for anchors defining a hypertext
368-
* source link. It indicates the link target, either a URL or a URL fragment.
369-
* A URL fragment is a name preceded by a hash mark (#), which specifies an
370-
* internal target location (an ID) within the current document. URLs are not
371-
* restricted to Web (HTTP)-based documents. URLs might use any protocol
372-
* supported by the browser. For example, file, ftp, and mailto work in most
373-
* user agents.
374-
*
375-
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-href
376-
*/
377-
lazy val href: Prop[String, String] = stringProp("href")
378-
379-
380355
/**
381356
* This enumerated attribute defines the pragma that can alter servers and
382357
* user-agents behavior. The value of the pragma is defined using the content
@@ -666,18 +641,6 @@ trait Props {
666641
lazy val spellCheck: Prop[Boolean, Boolean] = boolProp("spellcheck")
667642

668643

669-
/**
670-
* If the value of the type attribute is image, this attribute specifies a URI
671-
* for the location of an image to display on the graphical submit button;
672-
* otherwise it is ignored.
673-
*
674-
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-src
675-
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#src
676-
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-src
677-
*/
678-
lazy val src: Prop[String, String] = stringProp("src")
679-
680-
681644
/**
682645
* This integer attribute indicates if the element can take input focus (is
683646
* focusable), if it should participate to sequential keyboard navigation, and

shared/src/main/scala/com/raquo/domtypes/defs/attrs/HtmlAttrDefs.scala

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,29 @@ object HtmlAttrDefs {
6969
docUrls = Nil,
7070
),
7171

72+
// This is NOT a true reflected attribute – the `formAction` prop value does not match the
73+
// `formAction` attribute value when reading: the prop contains the full absolute URL,
74+
// whereas the attr can have a relative URL if that's what you provide as its value.
75+
// Also, if formAction is not set for this input element, the attr value is an empty string,
76+
// whereas the prop value contains the value of the form's action property.
77+
AttrDef(
78+
tagType = HtmlTagType,
79+
scalaName = "formAction",
80+
domName = "formaction",
81+
namespace = None,
82+
scalaValueType = "String",
83+
codec = "StringAsIs",
84+
commentLines = List(
85+
"The `formaction` attribute provides the URL that will process the input control ",
86+
"when the form is submitted and overrides the default `action` attribute of the ",
87+
"`form` element. This should be used only with `input` elements of `type` ",
88+
"submit or image.",
89+
),
90+
docUrls = List(
91+
"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#formaction",
92+
),
93+
),
94+
7295
AttrDef(
7396
tagType = HtmlTagType,
7497
scalaName = "formId",
@@ -98,6 +121,30 @@ object HtmlAttrDefs {
98121
),
99122
),
100123

124+
// This is NOT a true reflected attribute – the `href` prop value does not match the
125+
// `href` attribute value when reading: the prop contains the full absolute URL,
126+
// whereas the attr can have a relative URL if that's what you provide as its value.
127+
AttrDef(
128+
tagType = HtmlTagType,
129+
scalaName = "href",
130+
domName = "href",
131+
namespace = None,
132+
scalaValueType = "String",
133+
codec = "StringAsIs",
134+
commentLines = List(
135+
"This is the single required attribute for anchors defining a hypertext",
136+
"source link. It indicates the link target, either a URL or a URL fragment.",
137+
"A URL fragment is a name preceded by a hash mark (#), which specifies an",
138+
"internal target location (an ID) within the current document. URLs are not",
139+
"restricted to Web (HTTP)-based documents. URLs might use any protocol",
140+
"supported by the browser. For example, file, ftp, and mailto work in most",
141+
"user agents.",
142+
),
143+
docUrls = List(
144+
"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-href",
145+
),
146+
),
147+
101148
AttrDef(
102149
tagType = HtmlTagType,
103150
scalaName = "listId",
@@ -147,6 +194,27 @@ object HtmlAttrDefs {
147194
),
148195
),
149196

197+
// This is NOT a true reflected attribute – the `src` prop value does not match the
198+
// `src` attribute value when reading: the prop contains the full absolute URL,
199+
// whereas the attr can have a relative URL if that's what you provide as its value.
200+
AttrDef(
201+
tagType = HtmlTagType,
202+
scalaName = "src",
203+
domName = "src",
204+
namespace = None,
205+
scalaValueType = "String",
206+
codec = "StringAsIs",
207+
commentLines = List(
208+
"Specifies the URL of an image for `<img>` tag, for `type=\"image\"` input buttons, ",
209+
"or the URL of some other network resources like `<iframe>`.",
210+
),
211+
docUrls = List(
212+
"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-src",
213+
"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#src",
214+
"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-src",
215+
),
216+
),
217+
150218
AttrDef(
151219
tagType = HtmlTagType,
152220
scalaName = "stepAttr",

shared/src/main/scala/com/raquo/domtypes/defs/reflectedAttrs/ReflectedHtmlAttrDefs.scala

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -385,25 +385,6 @@ object ReflectedHtmlAttrDefs {
385385
),
386386
),
387387

388-
ReflectedHtmlAttrDef(
389-
scalaName = "formAction",
390-
domAttrName = "formaction",
391-
domPropName = "formAction",
392-
scalaValueType = "String",
393-
domPropValueType = "String",
394-
attrCodec = "StringAsIs",
395-
propCodec = "StringAsIs",
396-
commentLines = List(
397-
"The `formaction` attribute provides the URL that will process the input control",
398-
"when the form is submitted and overrides the default `action` attribute of the",
399-
"`form` element. This should be used only with `input` elements of `type`",
400-
"submit or image.",
401-
),
402-
docUrls = List(
403-
"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#formaction",
404-
),
405-
),
406-
407388
ReflectedHtmlAttrDef(
408389
scalaName = "formEncType",
409390
domAttrName = "formenctype",
@@ -521,28 +502,6 @@ object ReflectedHtmlAttrDefs {
521502
),
522503
),
523504

524-
ReflectedHtmlAttrDef(
525-
scalaName = "href",
526-
domAttrName = "href",
527-
domPropName = "href",
528-
scalaValueType = "String",
529-
domPropValueType = "String",
530-
attrCodec = "StringAsIs",
531-
propCodec = "StringAsIs",
532-
commentLines = List(
533-
"This is the single required attribute for anchors defining a hypertext",
534-
"source link. It indicates the link target, either a URL or a URL fragment.",
535-
"A URL fragment is a name preceded by a hash mark (#), which specifies an",
536-
"internal target location (an ID) within the current document. URLs are not",
537-
"restricted to Web (HTTP)-based documents. URLs might use any protocol",
538-
"supported by the browser. For example, file, ftp, and mailto work in most",
539-
"user agents.",
540-
),
541-
docUrls = List(
542-
"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-href",
543-
),
544-
),
545-
546505
ReflectedHtmlAttrDef(
547506
scalaName = "httpEquiv",
548507
domAttrName = "http-equiv",
@@ -1032,26 +991,6 @@ object ReflectedHtmlAttrDefs {
1032991
),
1033992
),
1034993

1035-
ReflectedHtmlAttrDef(
1036-
scalaName = "src",
1037-
domAttrName = "src",
1038-
domPropName = "src",
1039-
scalaValueType = "String",
1040-
domPropValueType = "String",
1041-
attrCodec = "StringAsIs",
1042-
propCodec = "StringAsIs",
1043-
commentLines = List(
1044-
"If the value of the type attribute is image, this attribute specifies a URI",
1045-
"for the location of an image to display on the graphical submit button;",
1046-
"otherwise it is ignored.",
1047-
),
1048-
docUrls = List(
1049-
"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-src",
1050-
"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#src",
1051-
"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-src",
1052-
),
1053-
),
1054-
1055994
ReflectedHtmlAttrDef(
1056995
scalaName = "tabIndex",
1057996
domAttrName = "tabindex",

0 commit comments

Comments
 (0)