-
-
Notifications
You must be signed in to change notification settings - Fork 145
Conversation
@chriddyp To keep DRY 🐫 we might need a similar mechanism to share some of the global attributes definition like in HTML components. |
Yeah I agree. I'd like to punt this one to the future. For now, just want to make sure that we won't be breaking any valid code. |
Alright, I've addressed your comments @alexcjohnson @byronz |
CHANGELOG.md
Outdated
- `inputmode` is now `inputMode` | ||
- `maxlength` is now `maxLength` | ||
- `minlength` is now `minLength` | ||
- Updated property definitions of various components in anticipation of upcoming component validation (https://github.com/plotly/dash-renderer/pull/100/). [#523](https://github.com/plotly/dash-core-components/pull/523/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, or fixed? Perhaps "improved" since it's a little of each I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for improved, or we could have two categories in release log: 1 bug fix 2 feature enhancement
src/components/Input.react.js
Outdated
@@ -62,7 +62,7 @@ export default class Input extends Component { | |||
if (setProps) { | |||
const payload = { | |||
n_blur: this.props.n_blur + 1, | |||
n_blur_timestamp: new Date(), | |||
n_blur_timestamp: new Date.now(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change #467 - yes, we should do it, but we should call it out.
src/components/Input.react.js
Outdated
debounce: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.bool | ||
]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's string for here? Describe it in the docstring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^^ applies to a bunch of these where either string or bool now accepts either... it's not clear to me which strings do what, or if they all evaluate to booleans or do something else entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one was wrong actually - only bool
. But for the other HTML boolean properties, HTML5 defines the only accepted values as the name of the attribute (case insensitive) or ""
: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes
That is, for autoFocus
, the following assignments mean "turn on autofocus": autoFocus=""
, autoFocus="autoFocus"
, autoFocus="autofocus"
, autoFocus="AUTOFOCUS"
And in order for it to be "turned off", it has to be omitted.
It seems like browsers are a little more loose and they evaluate these strings to be "If it's supplied, then it's applied" - it doesn't need to be the name of the attribute. This ends up being confusing because checked="false"
is actually "turn on checked" because it's applied. MDN says:
To be clear, the values "true" and "false" are not allowed on boolean attributes. To represent a false value, the attribute has to be omitted altogether. This restriction clears up some common misunderstandings: With checked="false" for example, the element’s checked attribute would be interpreted as true because the attribute is present.
So, we could either:
- Just keep it as a string and allow users to navigate this spec. Move on for now and revist later.
- Provide a preference but allow all strings:
autoFocus: oneOfType([oneOf(['autoFocus', 'autofocus', '']), propTypes.string])
- Be more opionated and only include the common forms like
'autoFocus': oneOf(['', 'autoFocus', 'autofocus', 'AUTOFOCUS'])
but omit the other permutations likeauToFoCus
that are technically valid. - Be even more opinionated and only include the most sane-looking version:
autoFocus='autoFocus'
and omit the other versions that are technically valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I prefer 2 or 3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So does false
(not 'false'
) turn autoFocus
off? Or is None
-> null
the only value that disables it?
If this check is only applied in dev mode, I'd vote to be more opinionated - (3) seems reasonable, plus false
if that's allowed to disable. I'd omit ''
unless it's particularly common usage, as explicitly allowing a normally falsy value to mean true is bound to cause confusion. Either way we should document a recommended value, something like:
autoFocus is enabled by
'autoFocus'
, but alternate capitalizations'autofocus'
and'AUTOFOCUS'
are also accepted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that false
ended up getting rendered as 'false'
looks like I'm wrong about that:
(https://codepen.io/chriddyp/pen/MREmpK?editors=0010)
Similarly in our toolchain:
import dash
import dash_html_components as html
import dash_core_components as dcc
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Input(id='1', readOnly=True),
dcc.Input(id='2', readOnly=False),
dcc.Input(id='3', readOnly='readonly'),
dcc.Input(id='4', readOnly='readOnly'),
dcc.Input(id='5', readOnly='true'),
dcc.Input(id='6', readOnly='false'),
dcc.Input(id='7', readOnly=''),
dcc.Input(id='8', readOnly='""'),
])
if __name__ == '__main__':
app.run_server(debug=True)
#7
is pretty confusing - to get ""
into the DOM, you have to pass in '""'
not ''
So I suppose we could allow boolean
for these properties as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oy, 7 is insane, definitely do not allow any version of that! So yeah, true
, false
, and a couple of capitalizations of autoFocus
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a small section about the attributes in dash-docs might be necessary given all the experiments we have, as most of our audiences are not Frontend expert, we should align the preference in the demo code too
.circleci/config.yml
Outdated
@@ -27,7 +27,7 @@ jobs: | |||
name: Install dependencies (dash) | |||
command: | | |||
git clone [email protected]:plotly/dash.git | |||
git clone [email protected]:plotly/dash-renderer.git | |||
git clone --branch chriddyp-dev-tools [email protected]:plotly/dash-renderer.git |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove this before merging. Just making sure that the other repo's prop checking doesn't cause these tests to fail.
@@ -162,19 +162,30 @@ Input.propTypes = { | |||
/** | |||
* This attribute indicates whether the value of the control can be automatically completed by the browser. | |||
*/ | |||
autocomplete: PropTypes.string, | |||
autoComplete: PropTypes.string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, given the complexity of autoComplete, I think string
is a good compromise for now
Alright, this is passing with the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💃
that's the only error left |
Odd - the new screenshots match the date supplied exactly. We send Odd that this behaviour would change in this PR. Looking into it... |
- boolean props - can be bools or strings, right? - number props - can be numbers or stringified numbers, right?
no way to specify that the values of an object need to be a certain type if the object has arbitrary key names.
this matches the other date properties most notably `n_clicks_timestamp`
3c4409a
to
41a3f31
Compare
OK - I've isolated the issue. There seems to be a problem with |
Here's a reproducable example that shows the issue (try editing the dates). I'll work on a fix in from datetime import datetime as dt
import dash
import dash_html_components as html
import dash_core_components as dcc
app = dash.Dash(__name__)
app.css.config.serve_locally = True
app.scripts.config.serve_locally = True
app.layout = html.Div([
html.Div([
html.Label('With ID'),
dcc.DatePickerSingle(id='date-picker-with-id'),
]),
html.Div([
html.Label('Without ID'),
dcc.DatePickerSingle(),
])
])
if __name__ == '__main__':
app.run_server(debug=True, dev_tools_hot_reload=False) |
as we’re not holding the date in state anymore
in preparation for plotly/dash-renderer#100