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

storage: Scroll dialog fields into view as needed #20060

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/storaged/block/format-dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ function format_dialog_internal(client, path, start, size, enable_dos_extended,
}
if (vals.type == "efi" && !vals.mount_point)
dlg.set_values({ mount_point: "/boot/efi" });
} else if (trigger == "crypto") {
if (vals.crypto != "none" && vals.crypto != " keep")
dlg.show_field("crypto_options", "end");
}
},
Action: {
Expand Down
40 changes: 37 additions & 3 deletions pkg/storaged/dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,15 @@ const Row = ({ field, values, errors, onChange }) => {
</>
);
return (
<FormGroup label={titleLabel} hasNoPaddingTop={field.hasNoPaddingTop}>
<FormGroup data-tag={tag} label={titleLabel} hasNoPaddingTop={field.hasNoPaddingTop}>
{ field_elts }
{ nested_elts }
<FormHelper helperText={explanation} helperTextInvalid={validated && error} />
</FormGroup>
);
} else if (!field.bare) {
return (
<FormGroup validated={validated} hasNoPaddingTop={field.hasNoPaddingTop}>
<FormGroup data-tag={tag} validated={validated} hasNoPaddingTop={field.hasNoPaddingTop}>
{ field_elts }
{ nested_elts }
<FormHelper helperText={explanation} helperTextInvalid={validated && error} />
Expand Down Expand Up @@ -465,14 +465,46 @@ export const dialog_open = (def) => {
return null;
})).then(results => {
const errors = { };
fields.forEach((f, i) => { if (results[i]) errors[f.tag] = results[i]; });
let scrolled = false;
fields.forEach((f, i) => {
if (results[i]) {
if (!scrolled) {
show_field(f.tag);
scrolled = true;
}
errors[f.tag] = results[i];
}
});
if (Object.keys(errors).length > 0)
return Promise.reject(errors);
});
};

const dlg = show_modal_dialog(props(), footer_props(null, null));

function show_field(tag, align) {
function scroll() {
const dialog_element = document.querySelector('#dialog .pf-v5-c-modal-box__body');
const field_element = document.querySelector('#dialog [data-tag="' + tag + '"]');

if (field_element) {
if (dialog_element) {
// check if we need to scroll
const dialog_rect = dialog_element.getBoundingClientRect();
const field_rect = field_element.getBoundingClientRect();
if (field_rect.top >= dialog_rect.top && field_rect.bottom <= dialog_rect.bottom)
return;
}

field_element.scrollIntoView({ behavior: "smooth", block: align || "start" });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test. Details

}
}
// By the time show_field is called from the "update"
// callback, newly visible fields don't exist yet in the
// DOM, so delay the scrolling a bit.
window.setTimeout(scroll, 10);
}

const self = {
run: (title, promise) => {
update_footer(title, promise);
Expand Down Expand Up @@ -537,6 +569,8 @@ export const dialog_open = (def) => {
update();
},

show_field: show_field,

close: () => {
dlg.footerProps.dialog_done();
}
Expand Down