view_components icon indicating copy to clipboard operation
view_components copied to clipboard

Label `for` attribute incorrect when `scope_id_false: false`

Open myabc opened this issue 3 months ago • 2 comments

Description

The generated label for attribute value does not respect the scope_id_false: option on TextField.

Reproduction

  include Primer::ComponentTestHelpers

  class NoModelScopeForm < ApplicationForm
    form do |no_model_scope_form|
      no_model_scope_form.text_field(
        name: :ultimate_answer,
        label: "Ultimate answer",
        scope_name_to_model: false,
        scope_id_to_model: false,
        **(@id ? { id: @id } : {})
      )
    end

    def initialize(id: nil)
      @id = id
    end
  end

    model = DeepThought.new(42)

    render_in_view_context do
      primer_form_with(model: model, url: "/foo") do |f|
        render(NoModelScopeForm.new(f))
      end
    end

    puts rendered_content


Expected value

<primer-text-field class="FormControl width-full FormControl--fullWidth">
  <label for="ultimate_answer" class="FormControl-label">
    Ultimate answer
  </label>
  <div class="FormControl-input-wrap">

    <input name="ultimate_answer" id="ultimate_answer" aria-describedby="validation-8aef820b-8020-427a-a0e4-7fdefa498ac3"
      data-target="primer-text-field.inputElement " class="FormControl-input FormControl-medium" type="text" value="42" />
  </div>
  <!-- ... -->
</primer-text-field>

Actual value

<primer-text-field class="FormControl width-full FormControl--fullWidth">
  <label class="FormControl-label" for="deep_thought_ultimate_answer">
    Ultimate answer
  </label>
  <div class="FormControl-input-wrap">
  
    <input name="ultimate_answer" id="ultimate_answer" aria-describedby="validation-e5d33a6f-6e21-4ab2-a6fb-3f09b61f940c"
      data-target="primer-text-field.inputElement " class="FormControl-input FormControl-medium" type="text" value="42" />
  </div>
  <!-- ... -->
</primer-text-field>

myabc avatar Sep 24 '25 18:09 myabc

Hi @lesliecdubs thanks for assigning me on this! Is there anything I can do to get #3696 looked at? thank you!

myabc avatar Dec 11 '25 22:12 myabc

@myabc thanks for working on this! I see there was a review comment on that PR a few weeks ago (https://github.com/primer/view_components/pull/3696#discussion_r2557350394); could you please take a look and respond to that, and then re-request a review from @jonrohan and we'll get this moving again?

lesliecdubs avatar Dec 12 '25 17:12 lesliecdubs

@lesliecdubs apologies. I managed to overlook Jon's comment. I've now replied.

myabc avatar Dec 18 '25 00:12 myabc