Skip to content

Commit dd6ed5b

Browse files
committed
Add class to Input elements so that CSS rules can be scoped
1 parent a7a12d1 commit dd6ed5b

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
All notable changes to `dash` will be documented in this file.
33
This project adheres to [Semantic Versioning](https://semver.org/).
44

5+
## UNRELEASED
6+
7+
## Fixed
8+
9+
- [dash-embedded-component #83](https://github.com/plotly/dash-embedded-component/issues/83) CSS for input elements not scoped to Dash application
10+
511
## [2.11.1] - 2023-06-29
612

713
## Fixed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ export default class Input extends PureComponent {
6666
data-dash-is-loading={
6767
(loading_state && loading_state.is_loading) || undefined
6868
}
69+
className={`dash-input ${this.props.className || ''}`}
6970
ref={this.input}
7071
onBlur={this.onBlur}
7172
onChange={this.onChange}
7273
onKeyPress={this.onKeyPress}
7374
{...valprops}
7475
{...omit(
7576
[
77+
'className',
7678
'debounce',
7779
'value',
7880
'n_blur',
Lines changed: 2 additions & 2 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;
77
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22
from selenium.common.exceptions import WebDriverException
3+
from selenium.webdriver.common.by import By
34
from dash import Dash, Input, Output, dcc, html
45

56

@@ -72,3 +73,34 @@ def test_inbs002_user_class(dash_dcc):
7273
dash_dcc.wait_for_style_to_equal(".test-input-css input", "width", "420px")
7374

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

0 commit comments

Comments
 (0)