M3: a selected variant shows its Current variant, the set its property editor (#2346)

This commit is contained in:
bflatastic committed 2026-11-28 17:02:46 +07:00
1 parent 745fe1aae7
commit 4d3d4e4e5b
4 files changed
+77 -23

No files matched your search

+2 -1
View File
@@ -461,7 +461,8 @@ name = "English"
"Default" = "Default"
"Default content" = "Default content"
"Default value (the top-left variant)" = "Default value (the top-left variant)"
"This variant's value" = "This variant's value"
"Current variant" = "Current variant"
"Select component set" = "Select component set"
"Delay" = "Delay"
"Delete" = "Delete"
"Delete category (its annotations stay)" = "Delete category (its annotations stay)"
+45 -21
View File
@@ -38,12 +38,14 @@ pub fn instance_section(app: &mut FigApp, ui: &mut Ui, doc: &Document, sel: &[No
match &n.kind {
NodeKind::Instance { .. } => instance_ui(app, ui, doc, n),
NodeKind::ComponentSet { description } => {
properties_ui(app, ui, doc, n.id, None);
properties_ui(app, ui, doc, n.id);
description_ui(app, ui, n.id, description);
}
NodeKind::Component { description, .. } => {
let set = variant_set(doc, n.id);
properties_ui(app, ui, doc, set.unwrap_or(n.id), set.map(|_| n.id));
match variant_set(doc, n.id) {
Some(set) => current_variant_ui(app, ui, doc, n, set),
None => properties_ui(app, ui, doc, n.id),
}
description_ui(app, ui, n.id, description);
}
_ => {}
@@ -226,8 +228,43 @@ fn name_width(ui: &Ui, default_w: f32, max: f32) -> f32 {
(ui.available_width() - default_w - BUTTON - 2.0 * widgets::GUTTER).clamp(48.0, max)
}
/// Properties of a component or component set (`variant`: the set's variant that is selected).
fn properties_ui(app: &mut FigApp, ui: &mut Ui, doc: &Document, owner: NodeId, variant: Option<NodeId>) {
/// One variant of a set selected: a Current variant section, a dropdown of each variant property
/// set to this variant's value; choosing another renames this variant only, so nothing moves
/// (#2349). The set's properties are edited on the set, which the section's button selects (#2346).
fn current_variant_ui(app: &mut FigApp, ui: &mut Ui, doc: &Document, variant: &Node, set: NodeId) {
let t = Tokens::get(ui.ctx());
widgets::separator(ui);
if widgets::section_header(ui, tr("Current variant"), &[(Icon::ComponentSet, tr("Select component set"))], false) == Some(0) {
app.run("select.set", json!({"ids": [set]}));
}
let pairs = variant_props(&variant.name);
let options = variant_options(doc, set);
let order: Vec<String> = options.iter().map(|(k, _)| k.clone()).collect();
for (k, vals) in &options {
let cur = pairs.get(k).cloned().unwrap_or_default();
row(ui, 32.0, |ui| {
prop_label(ui, k, Icon::ComponentSet);
let w = ui.available_width().max(60.0);
let resp = widgets::dropdown(ui, &cur, w, None);
menu_popup(&resp).show(|ui| {
for v in vals {
if menu_item(ui, v, "") {
let mut pairs = pairs.clone();
pairs.insert(k.clone(), v.clone());
app.run("node.set", json!({"ids": [variant.id], "props": {"name": variant_name(&pairs, &order)}}));
ui.close();
}
}
});
});
}
if variant_conflicts(doc, set).iter().any(|g| g.contains(&variant.id)) {
widgets::note(ui, tr("Some variants have the same property values: give each one a unique combination"), t.warning);
}
}
/// Properties of a component or component set.
fn properties_ui(app: &mut FigApp, ui: &mut Ui, doc: &Document, owner: NodeId) {
let t = Tokens::get(ui.ctx());
let is_set = matches!(doc.node(owner).map(|n| &n.kind), Some(NodeKind::ComponentSet { .. }));
// Shared (non-variant) properties live on every variant; read them from the first.
@@ -273,9 +310,6 @@ fn properties_ui(app: &mut FigApp, ui: &mut Ui, doc: &Document, owner: NodeId, v
} else {
Default::default()
};
// A selected variant's dropdowns show and set its own values (#2349); the set's, its default.
let own = variant.and_then(|v| doc.node(v)).map(|n| (n.id, variant_props(&n.name)));
let order: Vec<String> = variants.iter().map(|(k, _)| k.clone()).collect();
// Variant properties: name, values (the matrix), add value, delete. Dragged by their left
// margin to reorder them (only among themselves: the shared ones keep the engine's order).
let mut drag = ListDrag::in_order(ui, ("variant_props", owner));
@@ -291,22 +325,12 @@ fn properties_ui(app: &mut FigApp, ui: &mut Ui, doc: &Document, owner: NodeId, v
if let Some(nn) = widgets::text_field(ui, Id::unique(("vprop_name", owner, k.as_str())), k, name_w, tr("Name")) {
app.run("component.editProperty", json!({"id": owner, "name": k, "newName": nn}));
}
let def = own.as_ref().map_or(&defaults, |(_, pairs)| pairs).get(k).or(vals.first()).cloned().unwrap_or_default();
let hint = if own.is_some() { tr("This variant's value") } else { tr("Default value (the top-left variant)") };
let resp = widgets::dropdown(ui, &def, DEFAULT_W, None).on_hover_text(hint);
let def = defaults.get(k).or(vals.first()).cloned().unwrap_or_default();
let resp = widgets::dropdown(ui, &def, DEFAULT_W, None).on_hover_text(tr("Default value (the top-left variant)"));
menu_popup(&resp).show(|ui| {
for v in vals {
if menu_item(ui, v, "") {
match &own {
Some((id, pairs)) => {
let mut pairs = pairs.clone();
pairs.insert(k.clone(), v.clone());
app.run("node.set", json!({"ids": [id], "props": {"name": variant_name(&pairs, &order)}}));
}
None => {
app.run("component.editProperty", json!({"id": owner, "name": k, "default": v}));
}
}
app.run("component.editProperty", json!({"id": owner, "name": k, "default": v}));
ui.close();
}
}
@@ -121,3 +121,31 @@ fn a_long_variant_dropdown_scrolls_within_the_viewport() {
};
assert_eq!(*component, variants[49], "picking the last variant from the scrolled menu switches the instance");
}
#[test]
fn a_selected_variant_shows_its_current_values_and_the_set_edits_the_properties() {
// #2346: one variant shows a Current variant section, not the set's property editor; its
// button selects the set, which has the editor.
let mut s = Session::new();
let mut variants = Vec::new();
for (k, name) in ["Looking=Top right", "Looking=Down left"].iter().enumerate() {
let f = id(s.execute("frame.create", &json!({"x": 0, "y": 20 + k * 44, "width": 80, "height": 30, "name": name})).unwrap());
variants.push(id(s.execute("component.create", &json!({"ids": [f]})).unwrap()));
}
let set = id(s.execute("component.combineVariants", &json!({"ids": variants})).unwrap());
s.execute("select.set", &json!({"ids": [variants[1]]})).unwrap();
let mut u = Ui::new(s);
u.ctx.enable_accesskit();
let labels = |nodes: &[Node]| nodes.iter().filter_map(|n| n.label().map(str::to_string)).collect::<Vec<_>>();
let nodes = tree(&mut u);
let shown = labels(&nodes);
assert!(!shown.iter().any(|l| l == "Delete property" || l == "Add variant with a new value"), "no set editor: {shown:?}");
let values = combos(&nodes);
assert!(values.contains(&"Down left".to_string()) && !values.contains(&"Top right".to_string()), "this variant's value: {values:?}");
let to_set = nodes.iter().find(|n| n.label() == Some("Select component set") && n.bounds().is_some()).expect("the button");
click(&mut u, centre(to_set));
u.frame(vec![]);
assert_eq!(u.app.session.selection(), [set]);
let shown = labels(&tree(&mut u));
assert!(shown.iter().any(|l| l == "Delete property"), "the set has the editor: {shown:?}");
}
+2 -1
View File
@@ -1,6 +1,6 @@
# Components, variants, styles and variables parity
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-27 · **Change:** minor (a page's background can follow a colour variable in the page's own mode, set from the Page section's variable button or `page.setBackground {color: {$var}}` (#2343); Swap library re-points the styles and variables of the library copies that stay, so instances placed after a swap follow it too (#2568); the Local variables window reorders variables: Move up and Move down (Alt+↑ / Alt+↓) on a row, Sort A to Z and Z to A on a collection or group, numbers by value (#2633); `library.swap` lists the unused copies of the old library it removes in `dropped` (#2569); with several instances selected, the Design panel shows the properties they share, Mixed where their values differ, and sets a value on all of them; an enabled library's styles are offered in the style pickers without opening the Assets tab first, and the picker filters its list by source (All libraries, This file, one library); with a variable group shown in the Local variables window, Create variable makes the variable in that group, and renaming a variable in its row changes the part shown and keeps its group; a layer inside an instance bound to a variable its main layer doesn't bind keeps that binding as an override when instances are relinked after an import, a detach or a restore, and when its value is set back to the main's, so a library copy or an edit of the main no longer drops it; switching variants keeps the text typed into an instance when the other variant nests that text layer in other frames, matched by its name; a main component copied from a library file and pasted into another file is an instance of it from that library, instead of a new main; copied variants pasted with their own set, or a layer in it, selected join the set as new variants; the Scale tool keeps variable-bound lengths scaled: a scaled instance keeps its bindings and draws them at the variable's value times its scale factor, other scaled layers keep the scaled value and drop the binding (#2090); a style of one library that reaches a file through another library's component is, in a file linking both, the first library's own bound copy, so its modes colour it (#2414); with a variant selected, its property dropdowns show its own values and choosing one renames only that variant, instead of setting the set's default and moving the variants (#2349); library analytics count insertions and detachments of styles and variables; combining components gives every variant the properties any of them had; the local variables JSON carries the file's text styles (`textStyles` in `variable.export`, read back by `variable.import` with their variable bindings re-pointed; a file's own export leaves its text styles alone) (#2173); renaming a variable group to a path with `/` nests it under a parent group instead of turning the slash into a hyphen (#2353); a group's context menu in the Local variables window has Duplicate group, a copy named after it plus " 2" holding a copy of every variable, in one undo step (#2084); pages take a variable mode: with nothing selected the Design panel's Page section shows a Variable modes section, Auto or a mode of each collection that has more than one, as the help center says ("Apply variable mode" in the Page section of the right sidebar) (#2215); a text style binds a number variable to its weight (#2174); an instance lists only the properties its variant's layers use and long property names are cut to one line (#2022); with several layers selected the Design panel header's component button offers Create multiple components (#2088); the Local variables window selects several variables (click, Shift+click for a range, Cmd/Ctrl+click to toggle, Escape to clear) and delete, move to a group and scope act on the selected local variables in one undo step (#2002); text styles carry paragraph spacing and indent, the list style and the OpenType features, as the Supported in text styles table of Create and apply text styles says (#1829); a layer's effect binding takes only a field its effect has; Go to main component on an instance of a library component opens the library file in a tab and selects the main there; glass effects take variables; Delete on a layer inside an instance hides it as an override instead of being refused, as the help center says: "Figma will only toggle the layer's visibility instead of removing it"; library analytics list how many layers and files use each style and variable; SwiftUI and Compose code names a bound variable by its iOS or Android code syntax; library analytics count insertions and show insertions and detachments over the past 30 days, 90 days or year; a collection of this file can be extended (Extend collection on its row, `variable.extendCollection`), its extension following its edits at once, and extended collections extend again in the file; a typed or stored variable, collection or mode id names only the object with that id (#1613); Line truncated
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-28 · **Change:** minor (one variant selected shows a Current variant section, a dropdown of each variant property at its value, and a button that selects the set, which has the property editor (#2346); a page's background can follow a colour variable in the page's own mode, set from the Page section's variable button or `page.setBackground {color: {$var}}` (#2343); Swap library re-points the styles and variables of the library copies that stay, so instances placed after a swap follow it too (#2568); the Local variables window reorders variables: Move up and Move down (Alt+↑ / Alt+↓) on a row, Sort A to Z and Z to A on a collection or group, numbers by value (#2633); `library.swap` lists the unused copies of the old library it removes in `dropped` (#2569); with several instances selected, the Design panel shows the properties they share, Mixed where their values differ, and sets a value on all of them; an enabled library's styles are offered in the style pickers without opening the Assets tab first, and the picker filters its list by source (All libraries, This file, one library); with a variable group shown in the Local variables window, Create variable makes the variable in that group, and renaming a variable in its row changes the part shown and keeps its group; a layer inside an instance bound to a variable its main layer doesn't bind keeps that binding as an override when instances are relinked after an import, a detach or a restore, and when its value is set back to the main's, so a library copy or an edit of the main no longer drops it; switching variants keeps the text typed into an instance when the other variant nests that text layer in other frames, matched by its name; a main component copied from a library file and pasted into another file is an instance of it from that library, instead of a new main; copied variants pasted with their own set, or a layer in it, selected join the set as new variants; the Scale tool keeps variable-bound lengths scaled: a scaled instance keeps its bindings and draws them at the variable's value times its scale factor, other scaled layers keep the scaled value and drop the binding (#2090); a style of one library that reaches a file through another library's component is, in a file linking both, the first library's own bound copy, so its modes colour it (#2414); with a variant selected, its property dropdowns show its own values and choosing one renames only that variant, instead of setting the set's default and moving the variants (#2349); library analytics count insertions and detachments of styles and variables; combining components gives every variant the properties any of them had; the local variables JSON carries the file's text styles (`textStyles` in `variable.export`, read back by `variable.import` with their variable bindings re-pointed; a file's own export leaves its text styles alone) (#2173); renaming a variable group to a path with `/` nests it under a parent group instead of turning the slash into a hyphen (#2353); a group's context menu in the Local variables window has Duplicate group, a copy named after it plus " 2" holding a copy of every variable, in one undo step (#2084); pages take a variable mode: with nothing selected the Design panel's Page section shows a Variable modes section, Auto or a mode of each collection that has more than one, as the help center says ("Apply variable mode" in the Page section of the right sidebar) (#2215); a text style binds a number variable to its weight (#2174); an instance lists only the properties its variant's layers use and long property names are cut to one line (#2022); with several layers selected the Design panel header's component button offers Create multiple components (#2088); the Local variables window selects several variables (click, Shift+click for a range, Cmd/Ctrl+click to toggle, Escape to clear) and delete, move to a group and scope act on the selected local variables in one undo step (#2002); text styles carry paragraph spacing and indent, the list style and the OpenType features, as the Supported in text styles table of Create and apply text styles says (#1829); a layer's effect binding takes only a field its effect has; Go to main component on an instance of a library component opens the library file in a tab and selects the main there; glass effects take variables; Delete on a layer inside an instance hides it as an override instead of being refused, as the help center says: "Figma will only toggle the layer's visibility instead of removing it"; library analytics list how many layers and files use each style and variable; SwiftUI and Compose code names a bound variable by its iOS or Android code syntax; library analytics count insertions and show insertions and detachments over the past 30 days, 90 days or year; a collection of this file can be extended (Extend collection on its row, `variable.extendCollection`), its extensLine truncated
Design systems are why teams adopt Figma. **Components: breadth ~96%, ready ~72%. Styles and
variables: breadth ~95%, ready ~76% (estimated).** QA'd with a synthetic design system of ~300
@@ -84,6 +84,7 @@ updates with overrides kept: `library_tests.rs`, `components_scale_tests.rs`.
| Date | Change | Summary |
|---|---|---|
| 2026-11-28 | patch | M3, #2346: one variant of a set selected showed the set's whole property editor (names, every value as a field, Add variant), so it wasn't clear which variant was selected and edits there changed the set. It now shows a Current variant section: one dropdown per variant property at this variant's value (choosing another renames this variant, #2349) and a button that selects the set, where the properties are edited. Test: `variant_own_value_tests::a_selected_variant_shows_its_current_values_and_the_set_edits_the_properties`. |
| 2026-11-23 | minor | M3: a main component copied from a library file and pasted into another file is an instance of it from that library, which gets enabled in that file, as pasting an instance of it already was and as Figma does with a published component. It used to paste a copy of the main, a new component of that file unlinked from the library. A variant pastes as an instance of that variant. A component the library doesn't offer (hidden from publishing, or added since the last publish) and a main from a file that publishes no library still paste as a copy. Test: `library::tests::a_main_pasted_from_its_library_file_is_an_instance_of_it`. Numbers unchanged |
| 2026-11-19 | patch | M3: copying a variant and pasting with that variant, a layer in it or its set selected pasted an instance on the page. Copied variants of one set now paste into that set as new variants (deep copies, as Duplicate makes), under the copied variants where they are now, below the lowest variant with the gap of 20 that Add variant leaves, and the set grows to hold them. Every other paste of a copied main still makes an instance: with nothing selected, into another set, a main that isn't a variant pasted with a set selected, Paste over and Paste to replace on a variant, and an explicit `parent` (even the variant's own set). Tests: `pasting_a_variant_with_its_set_selected_adds_a_variant_below_the_others`, `a_variant_pasted_into_its_set_after_the_set_moved_lands_under_the_variant`, `a_variant_pasted_with_another_set_selected_is_an_instance`, `a_main_that_is_no_variant_pasted_with_a_set_selected_is_an_instance`, `a_variant_pasted_with_its_own_set_as_an_explicit_parent_is_an_instance`, `pasting_over_or_replacing_a_variant_makes_an_instance_of_the_copied_variant` |
| 2026-11-22 | patch | M3: switching an instance to another variant put back the variant's own text in place of the text typed into it when the two variants nest that text layer in different frames (`text › Label` in one, `div › text › Label` in the other), because the typed layer was matched to the new variant's by name path only. Now a text layer of the new variant nothing else matched takes the old text layer of the same name, when exactly one layer on each side has that name; layers inside nested instances still go by their own mains. Two layers of one name stay unmatched, since either could be the one typed into. Test: `typed_text_stays_across_variants_that_nest_it_differently`. Grade unchanged. |