Skip to content

Commit 1f7f921

Browse files
committed
Merge branch 'v4' into feature/dcc-refactor-textarea-tooltip
2 parents e0e3a60 + 391f0c8 commit 1f7f921

File tree

7 files changed

+53
-18
lines changed

7 files changed

+53
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
88

99
- Dropdown API changes
1010
* default value of optionHeight is now 'auto' which supports text wrapping of lengthy text on small screens; you can still specify a numeric pixel height if desired
11-
* new `localizations` prop to customize strings used within the component
11+
* new `labels` prop to customize strings used within the component
1212
* default value for closeOnSelect is now `True` for single-select dropdowns and `False` for multi-select
1313

1414
- Slider API changes

components/dash-core-components/src/components/css/sliders.css

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
touch-action: none;
88
width: 100%;
99
height: 14px;
10-
padding: 8px 0 28px 0;
10+
padding: 18px 0 18px 0;
1111
box-sizing: border-box;
1212
/* Override Radix's default margin/padding behavior */
1313
--radix-slider-thumb-width: 16px;
1414
}
1515

16+
.dash-slider-root.has-marks {
17+
padding: 8px 0 28px 0;
18+
}
19+
1620
.dash-slider-root[data-orientation='vertical'].has-marks {
1721
padding-bottom: 0px;
1822
}
@@ -167,7 +171,7 @@
167171
.dash-slider-container {
168172
display: flex;
169173
align-items: center;
170-
gap: 12px;
174+
gap: 16px;
171175
width: 100%;
172176
}
173177

@@ -184,7 +188,7 @@
184188
}
185189

186190
.dash-range-slider-min-input {
187-
min-width: 64px;
191+
text-align: center;
188192
}
189193

190194
.dash-range-slider-max-input {
@@ -193,7 +197,7 @@
193197

194198
.dash-range-slider-input {
195199
width: 64px;
196-
margin-top: 8px;
200+
text-align: center;
197201
-webkit-appearance: textfield;
198202
-moz-appearance: textfield;
199203
appearance: textfield;

components/dash-core-components/src/fragments/RangeSlider.tsx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,35 @@ export default function RangeSlider(props: RangeSliderProps) {
166166
});
167167
}, [min, max, processedMarks, step, sliderWidth]);
168168

169+
// Calculate dynamic input width based on digits needed and container size
170+
const inputWidth = useMemo(() => {
171+
if (!sliderWidth) {
172+
return '64px'; // fallback to current width
173+
}
174+
175+
// Count digits needed for min and max values
176+
const maxDigits = Math.max(
177+
String(Math.floor(Math.abs(minMaxValues.max_mark))).length,
178+
String(Math.floor(Math.abs(minMaxValues.min_mark))).length
179+
);
180+
181+
// Add 1 for minus sign if min is negative
182+
const totalChars = maxDigits + (minMaxValues.min_mark < 0 ? 1 : 0);
183+
184+
// Calculate width as percentage of container (5% min, 15% max)
185+
/* eslint-disable no-magic-numbers */
186+
const minWidth = sliderWidth * 0.05;
187+
const maxWidth = sliderWidth * 0.15;
188+
const charBasedWidth = totalChars * 12; // approx 12px per character
189+
/* eslint-enable no-magic-numbers */
190+
191+
const calculatedWidth = Math.max(
192+
minWidth,
193+
Math.min(maxWidth, charBasedWidth)
194+
);
195+
return `${calculatedWidth}px`;
196+
}, [sliderWidth, minMaxValues.min_mark, minMaxValues.max_mark]);
197+
169198
const handleValueChange = (newValue: number[]) => {
170199
let adjustedValue = newValue;
171200

@@ -203,6 +232,7 @@ export default function RangeSlider(props: RangeSliderProps) {
203232
<input
204233
type="number"
205234
className="dash-input-container dash-range-slider-input dash-range-slider-min-input"
235+
style={{width: inputWidth}}
206236
value={value[0] ?? ''}
207237
onChange={e => {
208238
const inputValue = e.target.value;
@@ -263,7 +293,8 @@ export default function RangeSlider(props: RangeSliderProps) {
263293
{showInputs && !vertical && (
264294
<input
265295
type="number"
266-
className="dash-input-container dash-range-slider-input dash-range-slider-max-input"
296+
className="dash-input-container dash-range-slider-input dash-range-slider-max-input"
297+
style={{width: inputWidth}}
267298
value={value[value.length - 1] ?? ''}
268299
onChange={e => {
269300
const inputValue = e.target.value;

components/dash-core-components/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ export interface DropdownProps extends BaseComponentProps<DropdownProps> {
416416
style?: React.CSSProperties;
417417

418418
/**
419-
* Translations for customizing text contained within this component.
419+
* Text for customizing the labels rendered by this component.
420420
*/
421421
labels?: {
422422
select_all?: string;

components/dash-core-components/tests/integration/dropdown/test_localization.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ def test_ddlo001_translations(dash_duo):
3434
".dash-dropdown-action-button:last-child", "Désélectionner tout"
3535
)
3636

37-
search_input = dash_duo.find_element(".dash-dropdown-search")
38-
assert search_input.accessible_name == "Rechercher"
37+
assert (
38+
dash_duo.find_element(".dash-dropdown-search").accessible_name == "Rechercher"
39+
)
3940

40-
search_input.send_keys(1)
41+
dash_duo.find_element(".dash-dropdown-search").send_keys(1)
4142
assert dash_duo.find_element(".dash-dropdown-clear").accessible_name == "Annuler"
4243

4344
dash_duo.find_element(".dash-dropdown-action-button:first-child").click()
4445

45-
search_input.send_keys(9)
46+
dash_duo.find_element(".dash-dropdown-search").send_keys(9)
4647
assert dash_duo.find_element(".dash-dropdown-option").text == "Aucun d'options"
4748

4849
assert (
@@ -80,17 +81,16 @@ def test_ddlo002_partial_translations(dash_duo):
8081
".dash-dropdown-action-button:last-child", "Deselect All"
8182
)
8283

83-
search_input = dash_duo.find_element(".dash-dropdown-search")
84-
assert search_input.accessible_name == "Lookup"
84+
assert dash_duo.find_element(".dash-dropdown-search").accessible_name == "Lookup"
8585

86-
search_input.send_keys(1)
86+
dash_duo.find_element(".dash-dropdown-search").send_keys(1)
8787
assert (
8888
dash_duo.find_element(".dash-dropdown-clear").accessible_name == "Clear search"
8989
)
9090

9191
dash_duo.find_element(".dash-dropdown-action-button:first-child").click()
9292

93-
search_input.send_keys(9)
93+
dash_duo.find_element(".dash-dropdown-search").send_keys(9)
9494
assert dash_duo.find_element(".dash-dropdown-option").text == "No options found"
9595

9696
assert (

components/dash-core-components/tests/integration/misc/test_persistence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def make_output(*args):
168168
["4️⃣", "6️⃣"],
169169
"yes maybe",
170170
"r",
171-
[5, 9],
171+
[5, 8],
172172
22,
173173
"C",
174174
"knock knock\nwho's there?",

components/dash-core-components/tests/integration/sliders/test_sliders.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def update_output(value):
3030
dash_dcc.click_at_coord_fractions(slider, 0.5, 0.25)
3131
dash_dcc.wait_for_text_to_equal("#out", "You have selected 11")
3232
dash_dcc.click_at_coord_fractions(slider, 0.75, 0.25)
33-
dash_dcc.wait_for_text_to_equal("#out", "You have selected 17")
33+
dash_dcc.wait_for_text_to_equal("#out", "You have selected 16")
3434

3535
assert dash_dcc.get_logs() == []
3636

@@ -265,7 +265,7 @@ def update_output2(value):
265265

266266
dash_dcc.click_and_hold_at_coord_fractions(slider, 0.25, 0.25)
267267
dash_dcc.move_to_coord_fractions(slider, 0.75, 0.25)
268-
dash_dcc.wait_for_text_to_equal("#out-drag-value", "You have dragged 17")
268+
dash_dcc.wait_for_text_to_equal("#out-drag-value", "You have dragged 16")
269269
dash_dcc.move_to_coord_fractions(slider, 0.5, 0.25)
270270
dash_dcc.wait_for_text_to_equal("#out-drag-value", "You have dragged 11")
271271
dash_dcc.wait_for_text_to_equal("#out-value", "You have selected 5")

0 commit comments

Comments
 (0)