Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support horizontal orientation of radio buttons #3620

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/controls/css/widgets-base.css
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,19 @@
margin-bottom: var(--jp-widgets-radio-item-height-adjustment);
}

/* <DEPRECATED> */
.widget-radio-box-vertical, /* </DEPRECATED> */
.jupyter-widget-radio-box-vertical {
flex-direction: column;
}


/* <DEPRECATED> */
.widget-radio-box-horizontal, /* </DEPRECATED> */
.jupyter-widget-radio-box-horizontal {
flex-direction: row;
}

/* <DEPRECATED> */
.widget-radio-box label, /* </DEPRECATED> */
.jupyter-widget-radio-box label {
Expand All @@ -983,6 +996,11 @@
font-size: var(--jp-widgets-font-size);
}

.widget-radio-box-horizontal label,
.jupyter-widget-radio-box-horizontal label {
margin: 0 calc(var(--jp-widgets-input-padding) * 2) 0 0;
}

/* <DEPRECATED> */
.widget-radio-box input, /* </DEPRECATED> */
.jupyter-widget-radio-box input {
Expand Down
18 changes: 13 additions & 5 deletions packages/controls/src/widget_selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export class RadioButtonsModel extends SelectionModel {
tooltips: [],
icons: [],
button_style: '',
orientation:'vertical',
};
}
}
Expand All @@ -305,17 +306,24 @@ export class RadioButtonsView extends DescriptionView {
this.el.appendChild(this.container);
this.container.classList.add('widget-radio-box');

this.update();
this.update();
}

/**
* Update the contents of this view
*
* Called when the model is changed. The model may have been
* changed by another view or by a state update from the back-end.
* Called when the model is changed. The model may have been
* changed by another view or by a state update from the back-end.
*/
update(options?: any): void {
const items: string[] = this.model.get('_options_labels');
update(options?: any): void {
if (this.model.get('orientation') === 'vertical') {
this.container.classList.remove('widget-radio-box-horizontal');
this.container.classList.add('widget-radio-box-vertical');
} else {
this.container.classList.remove('widget-radio-box-vertical');
this.container.classList.add('widget-radio-box-horizontal');
}
const items: string[] = this.model.get('_options_labels');
const radios = Array.from(
this.container.querySelectorAll<HTMLInputElement>('input[type="radio"]')
).map((x) => x.value);
Expand Down
4 changes: 4 additions & 0 deletions python/ipywidgets/ipywidgets/widgets/widget_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@ class RadioButtons(_Selection):
_view_name = Unicode('RadioButtonsView').tag(sync=True)
_model_name = Unicode('RadioButtonsModel').tag(sync=True)

orientation = CaselessStrEnum(
values=['horizontal', 'vertical'], default_value='vertical',
help="Vertical or horizontal.").tag(sync=True)


@register
@doc_subst(_doc_snippets)
Expand Down