Skip to content

Commit

Permalink
Remove empty string from React DOM booleans/enums
Browse files Browse the repository at this point in the history
This is a design choice documented in
facebook#6727 (comment)
  • Loading branch information
motiz88 authored and Ville Saukkonen committed Mar 18, 2019
1 parent f91ffe3 commit 80c40c6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions lib/react-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ type ReactDOM$HTMLElementProps = ReactDOM$ElementProps & {
spellCheck?: ReactDOM$BooleanishString,
suppressContentEditableWarning?: boolean,
title?: string,
translate?: $TODO$CaseInsensitive<"" | "yes" | "no">
translate?: $TODO$CaseInsensitive<"yes" | "no">
};

type ReactDOM$SVGElementProps = ReactDOM$ElementProps & {
Expand All @@ -641,12 +641,10 @@ type ReactDOM$SVGElementProps = ReactDOM$ElementProps & {
};

type ReactDOM$BooleanishString =
| ""
| $TODO$CaseInsensitive<"true" | "false">
| boolean;

type ReactDOM$Boolean<AttributeName: string = ""> =
| ""
type ReactDOM$Boolean<AttributeName: string> =
| $TODO$CaseInsensitive<AttributeName>
| boolean;

Expand Down
2 changes: 1 addition & 1 deletion tests/react_dom/props_boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React from "react";
<span hidden={null} />; // Error: Expected DOM boolean
<span hidden="true" />; // Error: Expected DOM boolean
<span hidden="false" />; // Error: Expected DOM boolean
<span hidden="" />; // OK
<span hidden="" />; // Error: Expected DOM boolean
<span hidden="yes" />; // Error: Expected DOM boolean
<span hidden="hidden" />; // OK

Expand Down
2 changes: 1 addition & 1 deletion tests/react_dom/props_booleanish_string.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import React from "react";
<div contentEditable={null} />; // Error: Expected booleanish string
<div contentEditable="true" />; // OK
<div contentEditable="false" />; // OK
<div contentEditable="" />; // OK
<div contentEditable="" />; // Error: Expected booleanish string
<div contentEditable="yes" />; // Error: Expected booleanish string
<div contentEditable="contentEditable" />; // Error: Expected booleanish string

0 comments on commit 80c40c6

Please sign in to comment.