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

Table UI does not update when setting value programmatically while multiple=false #217

Open
mootari opened this issue Mar 21, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@mootari
Copy link
Member

mootari commented Mar 21, 2022

Create the following cells:

data = [{name: "foo"}, {name: "bar"}]
viewof table = Inputs.table(data, {multiple: false})
{
  viewof table.value = data[0];
  viewof table.dispatchEvent(new Event('input'));
}
table

Note that the value is assigned correctly (table would otherwise equal null), but the row is not marked as selected:

image

Expected:

image

@mootari
Copy link
Member Author

mootari commented Mar 21, 2022

Also mentioned here:

This particular case seems to be a bug in Inputs.table() though. With multiple: false, assigning a new value will update the view’s selection, but it won’t update the individual row inputs. (cc @mbostock)

@mootari
Copy link
Member Author

mootari commented Mar 21, 2022

Workaround:

// https://github.com/observablehq/inputs/issues/217#issuecomment-1074222779
setTableIndex = (table, index = -1) => {
  table.querySelector('input[type="radio"]:focus')?.blur();
  if(index >= 0) return table.querySelectorAll('input[type="radio"]')[index]?.onclick({});
  const c = table.querySelector('th input[type="checkbox"]:checked');
  if(!c) return;
  c.checked = false;
  c.onclick({});
}
// unset
setTableIndex(viewof table)
// set
setTableIndex(viewof table, 1)

@mbostock mbostock added the bug Something isn't working label Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants