Skip to content

Commit 1718ec0

Browse files
authored
Merge pull request #2589 from plotly/bugfix/dash-embedded-83
Bugfix: scope CSS of input elements
2 parents ce0aabe + ffcc9eb commit 1718ec0

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ This project adheres to [Semantic Versioning](https://semver.org/).
66

77
## Fixed
88

9+
- [#2589](https://github.com/plotly/dash/pull/2589) CSS for input elements not scoped to Dash application
10+
11+
## Changed
12+
913
- [#2593](https://github.com/plotly/dash/pull/2593) dcc.Input accepts a number for its debounce argument
1014

1115
## [2.11.1] - 2023-06-29

components/dash-core-components/src/components/Input.react.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,22 @@ export default class Input extends PureComponent {
7171
const valprops =
7272
this.props.type === 'number' ? {} : {value: this.state.value};
7373
const {loading_state} = this.props;
74+
let {className} = this.props;
75+
className = 'dash-input' + (className ? ` ${className}` : '');
7476
return (
7577
<input
7678
data-dash-is-loading={
7779
(loading_state && loading_state.is_loading) || undefined
7880
}
81+
className={className}
7982
ref={this.input}
8083
onBlur={this.onBlur}
8184
onChange={this.onChange}
8285
onKeyPress={this.onKeyPress}
8386
{...valprops}
8487
{...omit(
8588
[
89+
'className',
8690
'debounce',
8791
'value',
8892
'n_blur',
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
input:invalid {
1+
input.dash-input:invalid {
22
outline: solid red;
33
}
44

5-
input:valid {
5+
input.dash-input:valid {
66
outline: none black;
7-
}
7+
}

components/dash-core-components/tests/integration/input/test_input_basics.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,34 @@ def test_inbs002_user_class(dash_dcc):
7272
dash_dcc.wait_for_style_to_equal(".test-input-css input", "width", "420px")
7373

7474
assert dash_dcc.get_logs() == []
75+
76+
77+
def test_inbs003_styles_are_scoped(dash_dcc):
78+
app = Dash(__name__)
79+
80+
app.index_string = """
81+
<html>
82+
<body>
83+
<input id="ExternalInput" required />
84+
{%app_entry%}
85+
{%config%}
86+
{%scripts%}
87+
{%renderer%}
88+
</body>
89+
</html>
90+
"""
91+
92+
app.layout = html.Div(
93+
className="test-input-css",
94+
children=[dcc.Input(id="DashInput", required=True, className="unittest")],
95+
)
96+
97+
dash_dcc.start_server(app)
98+
99+
external_input = dash_dcc.find_element("#ExternalInput")
100+
dash_input = dash_dcc.find_element(".unittest")
101+
102+
external_outline_css = external_input.value_of_css_property("outline")
103+
dash_outline_css = dash_input.value_of_css_property("outline")
104+
105+
assert external_outline_css != dash_outline_css

0 commit comments

Comments
 (0)