Skip to content

Commit b05c848

Browse files
authored
Support horizontal orientation of radio buttons (#3620)
1 parent 3171b1c commit b05c848

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

packages/controls/css/widgets-base.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,19 @@
975975
margin-bottom: var(--jp-widgets-radio-item-height-adjustment);
976976
}
977977

978+
/* <DEPRECATED> */
979+
.widget-radio-box-vertical, /* </DEPRECATED> */
980+
.jupyter-widget-radio-box-vertical {
981+
flex-direction: column;
982+
}
983+
984+
985+
/* <DEPRECATED> */
986+
.widget-radio-box-horizontal, /* </DEPRECATED> */
987+
.jupyter-widget-radio-box-horizontal {
988+
flex-direction: row;
989+
}
990+
978991
/* <DEPRECATED> */
979992
.widget-radio-box label, /* </DEPRECATED> */
980993
.jupyter-widget-radio-box label {
@@ -983,6 +996,11 @@
983996
font-size: var(--jp-widgets-font-size);
984997
}
985998

999+
.widget-radio-box-horizontal label,
1000+
.jupyter-widget-radio-box-horizontal label {
1001+
margin: 0 calc(var(--jp-widgets-input-padding) * 2) 0 0;
1002+
}
1003+
9861004
/* <DEPRECATED> */
9871005
.widget-radio-box input, /* </DEPRECATED> */
9881006
.jupyter-widget-radio-box input {

packages/controls/src/widget_selection.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ export class RadioButtonsModel extends SelectionModel {
288288
tooltips: [],
289289
icons: [],
290290
button_style: '',
291+
orientation:'vertical',
291292
};
292293
}
293294
}
@@ -305,17 +306,24 @@ export class RadioButtonsView extends DescriptionView {
305306
this.el.appendChild(this.container);
306307
this.container.classList.add('widget-radio-box');
307308

308-
this.update();
309+
this.update();
309310
}
310311

311312
/**
312313
* Update the contents of this view
313314
*
314-
* Called when the model is changed. The model may have been
315-
* changed by another view or by a state update from the back-end.
315+
* Called when the model is changed. The model may have been
316+
* changed by another view or by a state update from the back-end.
316317
*/
317-
update(options?: any): void {
318-
const items: string[] = this.model.get('_options_labels');
318+
update(options?: any): void {
319+
if (this.model.get('orientation') === 'vertical') {
320+
this.container.classList.remove('widget-radio-box-horizontal');
321+
this.container.classList.add('widget-radio-box-vertical');
322+
} else {
323+
this.container.classList.remove('widget-radio-box-vertical');
324+
this.container.classList.add('widget-radio-box-horizontal');
325+
}
326+
const items: string[] = this.model.get('_options_labels');
319327
const radios = Array.from(
320328
this.container.querySelectorAll<HTMLInputElement>('input[type="radio"]')
321329
).map((x) => x.value);

python/ipywidgets/ipywidgets/widgets/widget_selection.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,10 @@ class RadioButtons(_Selection):
478478
_view_name = Unicode('RadioButtonsView').tag(sync=True)
479479
_model_name = Unicode('RadioButtonsModel').tag(sync=True)
480480

481+
orientation = CaselessStrEnum(
482+
values=['horizontal', 'vertical'], default_value='vertical',
483+
help="Vertical or horizontal.").tag(sync=True)
484+
481485

482486
@register
483487
@doc_subst(_doc_snippets)

0 commit comments

Comments
 (0)