-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from sul-dlss/t173-hide2
Adds update and display of file hidden attribute.
- Loading branch information
Showing
19 changed files
with
139 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class="form-check"> | ||
<%= render Elements::Forms::LabelComponent.new(form:, field_name:, label_text: label, hidden_label:, default_label_class: 'form-check-label') %> | ||
<%= render Elements::Forms::HelpTextComponent.new(id: help_text_id, help_text:) %> | ||
<%= form.checkbox field_name, class: 'form-check-input', required:, aria: field_aria, data: %> | ||
<%= render Elements::Forms::InvalidFeedbackComponent.new(form:, field_name:) %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module Elements | ||
module Forms | ||
# Component for form checkbox field | ||
class CheckboxComponent < Forms::FieldComponent | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<div> | ||
<%= render Elements::Forms::LabelComponent.new(form:, field_name:, label_text: label, hidden_label:) %> | ||
<%= render Elements::Forms::HelpTextComponent.new(id: help_text_id, help_text:) %> | ||
<%= form.file_field field_name, class: 'form-control', required:, aria: field_aria, multiple: true %> | ||
<%= form.file_field field_name, class: 'form-control', required:, aria: field_aria, multiple: true, data: %> | ||
<%= render Elements::Forms::InvalidFeedbackComponent.new(form:, field_name:) %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<div> | ||
<%= render Elements::Forms::LabelComponent.new(form:, field_name:, label_text: label, hidden_label:) %> | ||
<%= render Elements::Forms::HelpTextComponent.new(id: help_text_id, help_text:) %> | ||
<%= form.text_field field_name, class: 'form-control', required:, aria: field_aria %> | ||
<%= form.text_field field_name, class: 'form-control', required:, aria: field_aria, data: %> | ||
<%= render Elements::Forms::InvalidFeedbackComponent.new(form:, field_name:) %> | ||
</div> |
2 changes: 1 addition & 1 deletion
2
app/components/elements/forms/textarea_field_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<div> | ||
<%= render Elements::Forms::LabelComponent.new(form:, field_name:, label_text: label, hidden_label:) %> | ||
<%= render Elements::Forms::HelpTextComponent.new(id: help_text_id, help_text:) %> | ||
<%= form.textarea field_name, class: 'form-control', required:, aria: field_aria %> | ||
<%= form.textarea field_name, class: 'form-control', required:, aria: field_aria, data: %> | ||
<%= render Elements::Forms::InvalidFeedbackComponent.new(form:, field_name:) %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module ApplicationHelper | ||
def human_boolean(boolean) | ||
boolean ? 'Yes' : 'No' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Controller } from '@hotwired/stimulus' | ||
|
||
export default class extends Controller { | ||
submit (event) { | ||
event.preventDefault() | ||
event.target.form.requestSubmit() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
<tr> | ||
<td><%= content_file.filename %></td> | ||
<td> | ||
<%# turbo-frame and tables don't mix well: https://github.com/hotwired/turbo/issues/48 %> | ||
<%= turbo_frame_tag content_file do %> | ||
<div class="d-flex justify-content-between"> | ||
<div><%= content_file.label %></div> | ||
<div> | ||
<%= render Elements::ButtonLinkComponent.new(link: edit_content_file_path(content_file), variant: :'outline-secondary', size: :sm) do %> | ||
<%= edit_icon %><span class="visually-hidden">Edit</span> | ||
<% end %> | ||
</div> | ||
</div> | ||
<tr style="vertical-align: middle;"> | ||
<td><%= content_file.filename %></td> | ||
<td> | ||
<%# turbo-frame and tables don't mix well: https://github.com/hotwired/turbo/issues/48 %> | ||
<%= turbo_frame_tag content_file, 'description' do %> | ||
<div class="d-flex align-items-center justify-content-between"> | ||
<span><%= content_file.label %></span> | ||
<%= render Elements::ButtonLinkComponent.new(link: edit_content_file_path(content_file), variant: :'outline-secondary', size: :sm) do %> | ||
<%= edit_icon %><span class="visually-hidden">Edit</span> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
</td> | ||
<td> | ||
<%= turbo_frame_tag content_file, 'hide' do %> | ||
<%= form_with model: content_file do |form| %> | ||
<%= render Elements::Forms::CheckboxComponent.new(form:, field_name: :hide, hidden_label: true, data: { controller: 'form-submit', action: 'form-submit#submit' }) %> | ||
<% end %> | ||
</td> | ||
<td><%= number_to_human_size(content_file.size) %></td> | ||
<td> | ||
<%= render Elements::ButtonLinkComponent.new(link: content_file_path(content_file), variant: :'outline-secondary', size: :sm, data: { turbo_method: :delete, turbo_frame: dom_id(content_file.content, 'show') }) do %> | ||
<%= delete_icon %><span class="visually-hidden">Remove</span> | ||
<% end %> | ||
</td> | ||
<% end %> | ||
</td> | ||
<td> | ||
<%= render Elements::ButtonLinkComponent.new(link: content_file_path(content_file), variant: :'outline-secondary', size: :sm, data: { turbo_method: :delete, turbo_frame: dom_id(content_file.content, 'show') }) do %> | ||
<%= delete_icon %><span class="visually-hidden">Remove</span> | ||
<% end %> | ||
</td> | ||
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe Elements::Forms::CheckboxComponent, type: :component do | ||
let(:form) { ActionView::Helpers::FormBuilder.new(nil, work_form, vc_test_controller.view_context, {}) } | ||
let(:work_form) { WorkForm.new } | ||
let(:field_name) { 'title' } | ||
|
||
it 'creates field with label' do | ||
render_inline(described_class.new(form: form, field_name:)) | ||
expect(page).to have_css('label.form-check-label:not(.visually-hidden)', text: 'title') | ||
expect(page).to have_css('input.form-check-input[type="checkbox"]:not(.is-invalid)') | ||
expect(page).to have_no_css('small.form-text') | ||
expect(page).to have_no_css('div.invalid-feedback.is-invalid') | ||
end | ||
|
||
context 'when label is hidden' do | ||
it 'creates field with hidden label' do | ||
render_inline(described_class.new(form:, field_name:, hidden_label: true)) | ||
expect(page).to have_css('label.form-check-label.visually-hidden', text: 'title') | ||
end | ||
end | ||
|
||
context 'when help text is provided' do | ||
it 'creates field with help text' do | ||
render_inline(described_class.new(form:, field_name:, help_text: 'Helpful text')) | ||
expect(page).to have_css('input[aria-describedby="title_help"]') | ||
expect(page).to have_css('small.form-text[id="title_help"]', text: 'Helpful text') | ||
end | ||
end | ||
|
||
context 'when field has an error' do | ||
before do | ||
work_form.errors.add(field_name, 'is required') | ||
end | ||
|
||
it 'creates field with invalid feedback' do | ||
render_inline(described_class.new(form:, field_name:)) | ||
|
||
expect(page).to have_css('input.form-check-input.is-invalid') # rubocop:disable Capybara/SpecificMatcher | ||
expect(page).to have_css('div.invalid-feedback.is-invalid', text: 'is required') | ||
end | ||
end | ||
|
||
context 'when data is provided' do | ||
it 'creates field with data' do | ||
render_inline(described_class.new(form:, field_name:, data: { test: 'test_data' })) | ||
expect(page).to have_css('input[data-test="test_data"]') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters