Skip to content

Commit e3243f2

Browse files
authored
Merge pull request #547 from japgolly/attr
VDOM improvements
2 parents a1dd08e + d053f85 commit e3243f2

File tree

4 files changed

+87
-19
lines changed

4 files changed

+87
-19
lines changed

core/src/main/scala/japgolly/scalajs/react/vdom/Attr.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import Attr.ValueType
1212
/**
1313
* @tparam U Underlying type of the value required by this attribute.
1414
*/
15-
abstract class Attr[-U](final val name: String) {
16-
override final def toString = s"VdomAttr{name=$name}"
15+
abstract class Attr[-U](final val attrName: String) {
16+
override final def toString = s"VdomAttr{name=$attrName}"
1717

18-
override def hashCode = name.##
18+
override def hashCode = attrName.##
1919
override def equals(any: Any) = any match {
20-
case that: Attr[_] => this.name == that.name
20+
case that: Attr[_] => this.attrName == that.attrName
2121
case _ => false
2222
}
2323

@@ -51,9 +51,9 @@ object Attr {
5151
else
5252
Dud
5353

54-
class Generic[-U](name: String) extends Attr[U](name) {
54+
class Generic[-U](attrName: String) extends Attr[U](attrName) {
5555
override def :=[A](a: A)(implicit t: ValueType[A, U]): TagMod =
56-
t(name, a)
56+
t(attrName, a)
5757
}
5858

5959
final class Event[E[+x <: dom.Node] <: raw.SyntheticEvent[x]](name: String)
@@ -116,7 +116,7 @@ object Attr {
116116

117117
object Ref extends Attr[raw.React.RefFn[_ <: TopNode]]("ref") {
118118
override def :=[A](a: A)(implicit t: ValueType[A, raw.React.RefFn[_ <: TopNode]]) =
119-
t(name, a)
119+
t(attrName, a)
120120
private[vdom] def apply[N <: TopNode](r: japgolly.scalajs.react.Ref.Set[N]): TagMod =
121121
:=(r.rawSetFn)(ValueType.direct)
122122
}

core/src/main/scala/japgolly/scalajs/react/vdom/HtmlAttrs.scala

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,69 @@ trait HtmlAttrs {
223223

224224
final def autoCapitalize = VdomAttr("autoCapitalize")
225225

226-
/**
227-
* This attribute indicates whether the value of the control can be
226+
/** This attribute indicates whether the value of the control can be
228227
* automatically completed by the browser. This attribute is ignored if the
229228
* value of the type attribute is hidden, checkbox, radio, file, or a button
230229
* type (button, submit, reset, image).
231-
*
232-
* Possible values are "off" and "on"
233230
*/
234-
object autoComplete extends VdomAttr.Generic("autoComplete") {
235-
def on = this := "on"
236-
def off = this := "off"
231+
final object autoComplete extends VdomAttr.Generic("autoComplete") {
232+
def additionalName = this := "additional-name"
233+
def addressLevel1 = this := "address-level1"
234+
def addressLevel2 = this := "address-level2"
235+
def addressLevel3 = this := "address-level3"
236+
def addressLevel4 = this := "address-level4"
237+
def addressLine1 = this := "address-line1"
238+
def addressLine2 = this := "address-line2"
239+
def addressLine3 = this := "address-line3"
240+
def bday = this := "bday"
241+
def bdayDay = this := "bday-day"
242+
def bdayMonth = this := "bday-month"
243+
def bdayYear = this := "bday-year"
244+
def ccAdditionalName = this := "cc-additional-name"
245+
def ccCsc = this := "cc-csc"
246+
def ccExp = this := "cc-exp"
247+
def ccExpMonth = this := "cc-exp-month"
248+
def ccExpYear = this := "cc-exp-year"
249+
def ccFamilyName = this := "cc-family-name"
250+
def ccGivenName = this := "cc-given-name"
251+
def ccName = this := "cc-name"
252+
def ccNumber = this := "cc-number"
253+
def ccType = this := "cc-type"
254+
def country = this := "country"
255+
def countryName = this := "country-name"
256+
def currentPassword = this := "current-password"
257+
def email = this := "email"
258+
def familyName = this := "family-name"
259+
def givenName = this := "given-name"
260+
def honorificPrefix = this := "honorific-prefix"
261+
def honorificSuffix = this := "honorific-suffix"
262+
def impp = this := "impp"
263+
def language = this := "language"
264+
def name = this := "name"
265+
def newPassword = this := "new-password"
266+
def nickname = this := "nickname"
267+
def off = this := "off"
268+
def on = this := "on"
269+
def oneTimeCode = this := "one-time-code"
270+
def organization = this := "organization"
271+
def organizationTitle = this := "organization-title"
272+
def photo = this := "photo"
273+
def postalCode = this := "postal-code"
274+
def sex = this := "sex"
275+
def streetAddress = this := "street-address"
276+
def tel = this := "tel"
277+
def telAreaCode = this := "tel-area-code"
278+
def telCountryCode = this := "tel-country-code"
279+
def telExtension = this := "tel-extension"
280+
def telLocal = this := "tel-local"
281+
def telLocalPrefix = this := "tel-local-prefix"
282+
def telLocalSuffix = this := "tel-local-suffix"
283+
def telNational = this := "tel-national"
284+
def transactionAmount = this := "transaction-amount"
285+
def transactionCurrency = this := "transaction-currency"
286+
def url = this := "url"
287+
def username = this := "username"
288+
def usernameEmail = this := "username email"
237289
}
238290

239291
final def autoCorrect = VdomAttr[Boolean]("autoCorrect")
@@ -494,7 +546,7 @@ trait HtmlAttrs {
494546
*/
495547
final def max = VdomAttr("max")
496548

497-
final def maxLength = VdomAttr("maxLength")
549+
final def maxLength = VdomAttr[Int]("maxLength")
498550

499551
/**
500552
* This attribute specifies the media which the linked resource applies to.
@@ -531,7 +583,7 @@ trait HtmlAttrs {
531583
*/
532584
final def min = VdomAttr("min")
533585

534-
final def minLength = VdomAttr("minLength")
586+
final def minLength = VdomAttr[Int]("minLength")
535587

536588
final def multiple = VdomAttr[Boolean]("multiple")
537589

@@ -1041,6 +1093,13 @@ trait HtmlAttrs {
10411093
*/
10421094
final def optimum = VdomAttr("optimum")
10431095

1096+
/** The pattern attribute specifies a regular expression against which the control’s value, or, when the multiple
1097+
* attribute applies and is set, the control’s values, are to be checked.
1098+
*
1099+
* @see https://www.w3.org/TR/html5/sec-forms.html#the-pattern-attribute
1100+
*/
1101+
final def pattern = VdomAttr[String]("pattern")
1102+
10441103
/**
10451104
* A hint to the user of what can be entered in the control. The placeholder
10461105
* text must not contain carriage returns or line-feeds. This attribute

core/src/main/scala/japgolly/scalajs/react/vdom/HtmlStyles.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2514,7 +2514,9 @@ trait HtmlStyles {
25142514
* * . - a period signifies an empty grid cell
25152515
* * none - no grid areas are defined
25162516
*/
2517-
final def gridTemplateAreas = Style[String]("gridTemplateAreas")
2517+
final object gridTemplateAreas extends Style[String]("gridTemplateAreas") {
2518+
def apply(rows: String*) = this := rows.mkString("'", "' '", "'")
2519+
}
25182520

25192521
/**
25202522
* Specifies the size of the grid lines. You can think of it like setting the

doc/changelog/1.4.2.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@
66
* `AsyncCallback#flatten` wouldn't compile (oops)
77
* `AsyncCallback.fromFuture` should be sync if future already complete
88
* `AsyncCallback.promise` should be sync if promise already complete
9-
* Fix bug where in `fullOptJS`, using a key and a ref would result in the key being lost.
10-
* Fix CSS-Grid style definitions to not cause React warnings
9+
* Fix bug where in `fullOptJS`, using a key and a ref would result in the key being lost
1110

1211
* Add an immediately-deprecated `AsyncCallback.fromCallback[A](c: CallbackTo[A]): AsyncCallback[A]`
1312
which points users to use `c.asAsyncCallback`.
1413

14+
* VDOM improvements
15+
* Add helper methods to the `autoComplete` attribute, eg. `^.autoComplete.currentPassword`
16+
* `minLength` and `maxLength` now only accept ints
17+
* Add `pattern` attribute
18+
* Fix CSS-Grid style definitions to not cause React warnings
19+
* `gridTemplateAreas` has a new optional syntax: `^.gridTemplateAreas("a a", "b c", "b c")`
20+
which is equivalent to `^.gridTemplateAreas := "'a a' 'b c' 'b c'"`
21+
1522
* Dependency upgrades
1623
* Cats 1.6.0
1724
* Scala.JS 0.6.27

0 commit comments

Comments
 (0)