Skip to content

Commit d7fa1ac

Browse files
committed
Fix issues raised by tests
1 parent bed25f0 commit d7fa1ac

File tree

4 files changed

+70
-10
lines changed

4 files changed

+70
-10
lines changed

components/dash-core-components/src/components/Input.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ const defaultProps: Partial<InputProps> = {
286286
* the Checklist and RadioItems component. Dates, times, and file uploads
287287
* are also supported through separate components.
288288
*/
289-
export default function Input(props: InputProps) {
289+
function Input(props: InputProps) {
290290
props = {...defaultProps, ...props};
291291
const input = useRef(document.createElement('input'));
292292
const [value, setValue] = useState<InputProps['value']>(props.value);
@@ -466,14 +466,13 @@ export default function Input(props: InputProps) {
466466
<LoadingElement>
467467
{loadingProps => (
468468
<div
469-
id={props.id}
470469
className={`dash-input-container ${className}${
471470
props.type === 'hidden' ? ' dash-input-hidden' : ''
472471
}`.trim()}
473472
style={props.style}
474473
>
475474
<input
476-
id={inputId}
475+
id={props.id || inputId}
477476
ref={input}
478477
className="dash-input-element"
479478
onBlur={onBlur}
@@ -490,7 +489,7 @@ export default function Input(props: InputProps) {
490489
className="dash-input-stepper dash-stepper-decrement"
491490
onClick={() => handleStepperClick('decrement')}
492491
disabled={isDecrementDisabled}
493-
aria-controls={inputId}
492+
aria-controls={props.id || inputId}
494493
aria-label="Decrease value"
495494
>
496495
@@ -502,7 +501,7 @@ export default function Input(props: InputProps) {
502501
className="dash-input-stepper dash-stepper-increment"
503502
onClick={() => handleStepperClick('increment')}
504503
disabled={isIncrementDisabled}
505-
aria-controls={inputId}
504+
aria-controls={props.id || inputId}
506505
aria-label="Increase value"
507506
>
508507
+
@@ -513,3 +512,10 @@ export default function Input(props: InputProps) {
513512
</LoadingElement>
514513
);
515514
}
515+
516+
Input.dashPersistence = pick(
517+
['persisted_props', 'persistence_type'],
518+
defaultProps
519+
);
520+
521+
export default Input;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.test-input-css input {
1+
.test-input-css {
22
width: 420px;
33
border-color: hotpink;
44
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ def cb_render(*vals):
6262
def test_inbs002_user_class(dash_dcc):
6363
app = Dash(__name__, assets_folder="../../assets")
6464

65-
app.layout = html.Div(className="test-input-css", children=[dcc.Input()])
65+
app.layout = dcc.Input(className="test-input-css")
6666

6767
dash_dcc.start_server(app)
6868

6969
dash_dcc.wait_for_style_to_equal(
70-
".test-input-css input", "borderColor", "rgb(255, 105, 180)"
70+
".test-input-css", "borderColor", "rgb(255, 105, 180)"
7171
)
72-
dash_dcc.wait_for_style_to_equal(".test-input-css input", "width", "420px")
72+
dash_dcc.wait_for_style_to_equal(".test-input-css", "width", "420px")
7373

7474
assert dash_dcc.get_logs() == []
7575

@@ -97,7 +97,7 @@ def test_inbs003_styles_are_scoped(dash_dcc):
9797
dash_dcc.start_server(app)
9898

9999
external_input = dash_dcc.find_element("#ExternalInput")
100-
dash_input = dash_dcc.find_element(".unittest")
100+
dash_input = dash_dcc.find_element("#DashInput")
101101

102102
external_outline_css = external_input.value_of_css_property("outline")
103103
dash_outline_css = dash_input.value_of_css_property("outline")

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,60 @@ def test_inni003_invalid_numbers_range(dash_dcc, input_range_app):
6767
assert dash_dcc.get_logs() == []
6868

6969

70+
def test_inni004_steppers(dash_dcc, debounce_number_app):
71+
dash_dcc.start_server(debounce_number_app)
72+
73+
# Test input with min=10, max=10000, step=3 (#input-fast)
74+
input_elem = dash_dcc.find_element("#input-fast")
75+
increment_btn = dash_dcc.find_element("#input-fast~.dash-stepper-increment")
76+
decrement_btn = dash_dcc.find_element("#input-fast~.dash-stepper-decrement")
77+
78+
# Verify steppers exist
79+
assert increment_btn.is_displayed(), "Increment stepper should be visible"
80+
assert decrement_btn.is_displayed(), "Decrement stepper should be visible"
81+
82+
# Set initial value to 100
83+
input_elem.send_keys("100")
84+
dash_dcc.wait_for_text_to_equal("#div-fast", "100")
85+
86+
# Test increment stepper - should increase by step=3
87+
increment_btn.click()
88+
dash_dcc.wait_for_text_to_equal("#div-fast", "103")
89+
90+
# Test decrement stepper - should decrease by step=3
91+
decrement_btn.click()
92+
dash_dcc.wait_for_text_to_equal("#div-fast", "100")
93+
94+
# Test multiple increments
95+
increment_btn.click()
96+
increment_btn.click()
97+
dash_dcc.wait_for_text_to_equal("#div-fast", "106")
98+
99+
# Test that steppers respect min constraint
100+
dash_dcc.clear_input(input_elem)
101+
input_elem.send_keys("11") # Close to min=10
102+
decrement_btn.click() # Should go to 10 (min)
103+
dash_dcc.wait_for_text_to_equal("#div-fast", "10")
104+
105+
# Verify decrement button is disabled at minimum
106+
assert (
107+
decrement_btn.get_attribute("disabled") == "true"
108+
), "Decrement should be disabled at minimum"
109+
110+
# Test that steppers respect max constraint
111+
dash_dcc.clear_input(input_elem)
112+
input_elem.send_keys("9999") # Close to max=10000
113+
increment_btn.click() # Should go to 10000 (max)
114+
dash_dcc.wait_for_text_to_equal("#div-fast", "10000")
115+
116+
# Verify increment button is disabled at maximum
117+
assert (
118+
increment_btn.get_attribute("disabled") == "true"
119+
), "Increment should be disabled at maximum"
120+
121+
assert dash_dcc.get_logs() == []
122+
123+
70124
def test_inni010_valid_numbers(dash_dcc, ninput_app):
71125
dash_dcc.start_server(ninput_app)
72126
for num, op in (

0 commit comments

Comments
 (0)