-
Notifications
You must be signed in to change notification settings - Fork 140
Add tooltip to navList if the text is truncated
#2610
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
5b576ed
Skeleton for action-list web component
camertron 07760ca
add typscript functionailty
thesnowrose 02d5b0c
It works
camertron 5a94267
Add :truncate option (same as true); add previews
camertron a8b856c
add action list test
thesnowrose 8b4a175
undo package-lock changes, add new line for linter
thesnowrose 4e4f60f
add constants to json file, address errors
thesnowrose 501b598
Fix show more item
camertron a572c3c
fix constant error
thesnowrose 6021344
Generating component snapshots
thesnowrose 24a1016
add component specific tests
thesnowrose d7cdb81
Merge remote-tracking branch 'refs/remotes/origin/nav_list_tooltips_o…
thesnowrose 80d039b
linter
thesnowrose f3e3e2e
cleanup uncommented out code, remove constants from json
thesnowrose a0815ac
Add changeset
thesnowrose 1ea6c9d
update navlist html to load action list assets
thesnowrose 00e6634
Modify NavListElement and NavListGroupElement to inherit from ActionL…
camertron 2ccdd33
Test for visible tooltip when window shrinks
camertron fe6d06a
Fix CSS selectors test
camertron 70228c1
Pr feedback
thesnowrose 2b215ee
Merge branch 'main' into nav_list_tooltips_on_truncation
thesnowrose 200911a
Generating component snapshots
thesnowrose 37e45c8
Build
camertron e3cbaf1
convert ActionListElement to composition class
thesnowrose 5fc53fb
Merge remote-tracking branch 'refs/remotes/origin/nav_list_tooltips_o…
thesnowrose d9b36ed
Merge branch 'main' into nav_list_tooltips_on_truncation
camertron e5db6f9
Generating component snapshots
camertron 5f0efc4
Build
camertron c0dcbd0
Re-introduce <action-list> custom element; ensure top-level NavList i…
camertron cccae91
Generating component snapshots
camertron 8e61e91
Merge upstream
camertron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| --- | ||
| "@primer/view-components": minor | ||
| --- | ||
|
|
||
| Add the ability to show a tooltip for navlists on text truncation |
Binary file added
BIN
+12 KB
...ots.test.ts-snapshots/primer/alpha/action_list/long_label_with_tooltip/dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.1 KB
...-snapshots/primer/alpha/action_list/long_label_with_tooltip/dark_colorblind.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.2 KB
...t.ts-snapshots/primer/alpha/action_list/long_label_with_tooltip/dark_dimmed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12 KB
...apshots/primer/alpha/action_list/long_label_with_tooltip/dark_high_contrast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+55.9 KB
....test.ts-snapshots/primer/alpha/action_list/long_label_with_tooltip/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+56.4 KB
....test.ts-snapshots/primer/alpha/action_list/long_label_with_tooltip/focused.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.1 KB
...ts.test.ts-snapshots/primer/alpha/action_list/long_label_with_tooltip/light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12 KB
...snapshots/primer/alpha/action_list/long_label_with_tooltip/light_colorblind.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.2 KB
...pshots/primer/alpha/action_list/long_label_with_tooltip/light_high_contrast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.2 KB
...apshots.test.ts-snapshots/primer/beta/nav_list/long_label_with_tooltip/dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.3 KB
...t.ts-snapshots/primer/beta/nav_list/long_label_with_tooltip/dark_colorblind.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.3 KB
....test.ts-snapshots/primer/beta/nav_list/long_label_with_tooltip/dark_dimmed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.1 KB
...s-snapshots/primer/beta/nav_list/long_label_with_tooltip/dark_high_contrast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+56.9 KB
...hots.test.ts-snapshots/primer/beta/nav_list/long_label_with_tooltip/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+57.2 KB
...hots.test.ts-snapshots/primer/beta/nav_list/long_label_with_tooltip/focused.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.1 KB
...pshots.test.ts-snapshots/primer/beta/nav_list/long_label_with_tooltip/light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.1 KB
....ts-snapshots/primer/beta/nav_list/long_label_with_tooltip/light_colorblind.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.3 KB
...-snapshots/primer/beta/nav_list/long_label_with_tooltip/light_high_contrast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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,20 +1,22 @@ | ||
| <%= render(Primer::BaseComponent.new(tag: :div)) do %> | ||
| <% if acts_as_form_input? %> | ||
| <span data-list-inputs="true"> | ||
| <%= @form_builder.hidden_field(@input_name, multiple: multi_select?, skip_default_ids: true) %> | ||
| </span> | ||
| <% end %> | ||
| <% if heading %> | ||
| <%= heading %> | ||
| <% end %> | ||
| <%= render(Primer::BaseComponent.new(tag: :ul, **@system_arguments)) do %> | ||
| <% items.each_with_index do |item, index| %> | ||
| <%# the conditions here make sure two dividers are never rendered one after the other %> | ||
| <% if index > 0 && @show_dividers && !item.is_a?(Divider) && !items[index - 1].is_a?(Divider) %> | ||
| <%= render(Primer::Alpha::ActionList::Divider.new) %> | ||
| <action-list> | ||
| <%= render(Primer::BaseComponent.new(tag: :div)) do %> | ||
| <% if acts_as_form_input? %> | ||
| <span data-list-inputs="true"> | ||
| <%= @form_builder.hidden_field(@input_name, multiple: multi_select?, skip_default_ids: true) %> | ||
| </span> | ||
| <% end %> | ||
| <% if heading %> | ||
| <%= heading %> | ||
| <% end %> | ||
| <%= render(Primer::BaseComponent.new(tag: :ul, **@system_arguments)) do %> | ||
| <% items.each_with_index do |item, index| %> | ||
| <%# the conditions here make sure two dividers are never rendered one after the other %> | ||
| <% if index > 0 && @show_dividers && !item.is_a?(Divider) && !items[index - 1].is_a?(Divider) %> | ||
| <%= render(Primer::Alpha::ActionList::Divider.new) %> | ||
| <% end %> | ||
| <%= item %> | ||
| <% end %> | ||
| <%= item %> | ||
| <% end %> | ||
| <%= capture(&post_list_content_block) if post_list_content_block %> | ||
| <% end %> | ||
| <%= capture(&post_list_content_block) if post_list_content_block %> | ||
| <% end %> | ||
| </action-list> |
This file contains hidden or 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 hidden or 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,58 @@ | ||
| import {controller} from '@github/catalyst' | ||
|
|
||
| // eslint-disable-next-line custom-elements/no-exports-with-element | ||
| export class ActionListTruncationObserver { | ||
| resizeObserver = new ResizeObserver(entries => { | ||
| for (const entry of entries) { | ||
| const action = entry.target | ||
|
|
||
| if (action instanceof HTMLElement) { | ||
| this.update(action) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| constructor(el: HTMLElement) { | ||
| this.resizeObserver.observe(el) | ||
| } | ||
|
|
||
| unobserve(el: HTMLElement) { | ||
| this.resizeObserver.unobserve(el) | ||
| } | ||
|
|
||
| update(el: HTMLElement) { | ||
| const label = el.querySelector('.ActionListItem-label') | ||
| if (!label) return | ||
|
|
||
| const tooltip = el.querySelector('.ActionListItem-truncationTooltip') as HTMLElement | null | ||
| if (!tooltip) return | ||
|
|
||
| const isTruncated = label.scrollWidth > label.clientWidth | ||
|
|
||
| if (isTruncated) { | ||
| tooltip.style.display = '' | ||
| } else { | ||
| tooltip.style.display = 'none' | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @controller | ||
| // eslint-disable-next-line custom-elements/expose-class-on-global | ||
| export class ActionListElement extends HTMLElement { | ||
| #truncationObserver: ActionListTruncationObserver | ||
|
|
||
| connectedCallback() { | ||
| this.#truncationObserver = new ActionListTruncationObserver(this) | ||
| } | ||
|
|
||
| disconnectedCallback() { | ||
| this.#truncationObserver.unobserve(this) | ||
| } | ||
| } | ||
|
|
||
| declare global { | ||
| interface Window { | ||
| ActionListElement: typeof ActionListElement | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.