-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add HintComponent and ErrorMessageComponent #98
Add HintComponent and ErrorMessageComponent #98
Conversation
@Spone I updated that branch. I think it is ready for review |
The <%= form_for @user, builder: ViewComponent::Form::Builder do |f| %>
<%= f.label :password %>
<%= f.password_field :password, aria: { describedby: f.field_id(: password, :description) } %>
<div id="<%= f.field_id(:title, :description) %>">
<%= f.hint :password, 'The password should be at least 8 characters long' %>
<%= f.error_message :password %>
</div>
<% end %> Reference: https://github.com/rails/rails/blob/7-0-stable/actionview/CHANGELOG.md |
Based on https://gist.github.com/tmaier/22966c6bddac86e3612c8eddc072b919 Notable differences: - self.tag to override the tag used easily. I am not using tag_class, as this is not a classical form component - ErrorMessageComponent#messages is public so that one can override it, if necessary
- Rename #component to #rendered_component - Rename #subject to #component
251072a
to
a83381e
Compare
All issues should be fixed. Please re-run the CI pipeline |
Thank you @tmaier, we've scheduled some time next week to review this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly spec improvements here. @Spone, I feel like there should be a pattern within specs of component
referring to an instance of the ViewComponent to test, and rendered_component
referring to the rendered HTML output.
subject
should refer to the object that we're testing against, in any case. It's not always easy to whittle that down to just one thing, especially in cases where component
should respond to methods in a certain way (render?
, errors
) and rendered_component
should have also changed in response to that (showing the validation error or not), but helpers like have_attributes
can help with that. I finished a blog post that might help with that today if you're interested.
Co-authored-by: Simon Fish <si@mon.fish>
Co-authored-by: Simon Fish <si@mon.fish>
Co-authored-by: Simon Fish <si@mon.fish>
Co-authored-by: Simon Fish <si@mon.fish>
Co-authored-by: Simon Fish <si@mon.fish>
Co-authored-by: Simon Fish <si@mon.fish>
Thanks for the review. I accepted all your changes. |
@Spone can you re-run the CI pipeline, please? And consider to merge it, if it passes... |
Hi @tmaier sorry for the delay @Spone and I are really busy at work those days. Also thank you @boardfish for your review Thanks for your PR, all is looking good. |
I prefer "message" is also the word used in validation options, so the intent is clear if we reuse it. |
I think
|
Besides this: I fixed the specs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for adding this!
Closes #97
This is a Pull Request to add components for hints and error messages, as proposed in #36
I introduce here a class attribute called
tag
.tag_class
was not really a good fit for this use case.Please see, if this fits your idea for the gem.
Note: For some reason of my local setup, I was unable to test this at all. I hope the CI pipeline provides some insights :)
Open Topics
.class
class attributearia-describedby
. I think Rails 6.1 or 7.0 introduced a convenient helper for this. I am just unsure how it was called...#dom_id
#field_id