Skip to content
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

Fix page title length check when it has html #349

Merged
merged 5 commits into from
Jan 3, 2024
Merged

Fix page title length check when it has html #349

merged 5 commits into from
Jan 3, 2024

Conversation

yshmarov
Copy link
Contributor

@yshmarov yshmarov commented Jan 2, 2024

expectation:
Screenshot 2024-01-02 at 20 13 55
reality:
Screenshot 2024-01-02 at 20 15 38

this is because the inline title length can be max 34 characters.

but I am using some html around the actual text, so I have more characters.

this way I can ensure that title is inline

<% title_with_checkbox_selected_count = capture do %>
  <div>
    <span data-checkbox-selected-count-target="counter"></span>
    <%= t('.orders_selected') %>
  </div>
<% end %>

<%= polaris_page(
  title: title_with_checkbox_selected_count,
+  force_medium_title: true 
...
%>

@yshmarov yshmarov changed the title force_medium_title option page component: force_medium_title option Jan 2, 2024
@@ -44,8 +46,8 @@ def header_arguments
tag: "div",
classes: class_names(
"Polaris-Page-Header--mobileView",
"Polaris-Page-Header--mediumTitle": @title.present? && @title.length <= LONG_TITLE,
"Polaris-Page-Header--longTitle": @title.present? && @title.length > LONG_TITLE,
"Polaris-Page-Header--mediumTitle": @title.present? && (@force_medium_title || @title.length <= LONG_TITLE),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yshmarov Maybe stripping HTML from @title before checking length will be easier?
https://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html#method-i-strip_tags

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is indeed much better. I've updated

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 👍 Please check tests and we can merge it

@kirillplatonov kirillplatonov changed the title page component: force_medium_title option Fix page title length check when it has html Jan 3, 2024
@kirillplatonov kirillplatonov merged commit c6ee4df into baoagency:main Jan 3, 2024
4 checks passed
@yshmarov yshmarov deleted the option-to-force-medium-title branch January 3, 2024 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants