Form ignores Styled refinements such as gap_5()

Open Beginner friendly
#3,091 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
desktop

Research direction

Start in crates/component/src/form/form.rs at Form::render and compare it with Field's style handling. Reproduce the issue with the provided v_form().gap_5() example, then verify that caller-supplied spacing, padding, and background refinements affect the rendered form while its built-in layout still works.

Written by the indexing model from the issue text.

Description

Description

Form implements Styled and stores style refinements in its style field, but Form::render never applies self.style to the rendered element. As a result, style helpers called directly on v_form()/h_form(), such as .gap_5(), .p_5(), and .bg(...), are silently ignored.

This affects gpui-component 0.6.1 and is also present on the current main branch:

https://github.com/longbridge/gpui-kit/blob/main/crates/component/src/form/form.rs#L119-L150

Environment

  • GPUI (gpui-pre): v0.3.4
  • GPUI Component: v0.6.1
  • Platform: Windows 11, build 26100
  • Rust: 1.98.1

Steps to Reproduce

v_form()
    .gap_5()
    .child(field().child(div().child("One")))
    .child(field().child(div().child("Two")))

Other Styled methods applied directly to Form, for example .p_5() or .bg(rgb(0xff0000)), are ignored as well.

Expected

The fields should have the spacing requested by .gap_5() (20 px with the default rem size), and other style refinements should be applied to the rendered form container.

Actual

The form keeps its built-in vertical gap (8 px for the default size), regardless of .gap_5(). Other externally supplied style refinements are also discarded.

Styled::style() writes into Form::style:

impl Styled for Form {
    fn style(&mut self) -> &mut StyleRefinement {
        &mut self.style
    }
}

However, Form::render() builds and returns a new v_flex() without calling refine_style(&self.style). Other styled components, including Field, apply their stored refinement this way.

A possible fix is to apply the form refinement after its built-in layout defaults so caller-provided styles can override them:

v_flex()
    // built-in form layout...
    .refine_style(&self.style)
Dominant language
Rust
Stars
14.5k
Forks
897
Avg merge
13h 22m
Merged PRs (30d)
247

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from longbridge/gpui-kit

All issues in longbridge/gpui-kit

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.