Skip to content

feat: show selected item's icon in trigger label if applicable #884

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 9 commits into from
May 28, 2021

Conversation

arjunlalb
Copy link
Contributor

Description

show selected item's icon in trigger label if applicable

Testing

Manually verified. UT added.

Checklist:

  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

@arjunlalb arjunlalb requested a review from a team as a code owner May 27, 2021 18:33
@codecov
Copy link

codecov bot commented May 27, 2021

Codecov Report

Merging #884 (16983c3) into main (7e0fa79) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #884   +/-   ##
=======================================
  Coverage   85.35%   85.35%           
=======================================
  Files         801      801           
  Lines       16466    16468    +2     
  Branches     2066     2067    +1     
=======================================
+ Hits        14055    14057    +2     
  Misses       2379     2379           
  Partials       32       32           
Impacted Files Coverage Δ
projects/components/src/select/select.component.ts 94.82% <100.00%> (+0.18%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7e0fa79...16983c3. Read the comment docs.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

selectedOption: SelectOptionComponent<V> | undefined,
triggerIcon: string | undefined
): string | undefined {
if (selectedOption !== undefined && selectedOption?.icon !== undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

So we're favoring the selections icon in the trigger over the trigger's icon? that doesn't seem right to me, but I guess I'd also find it strange to use a trigger icon and individual icons together

Copy link
Contributor

Choose a reason for hiding this comment

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

(also, unnecessary first condition)

Suggested change
if (selectedOption !== undefined && selectedOption?.icon !== undefined) {
if (selectedOption?.icon !== undefined) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if there's a selection, we should show the selection's icon or nothing.
If there's no selection, show the trigger icon. That's the intent.

It doesn't make sense to show the regular trigger icon along with a selection. that would be confusing.

we already show selected label in the trigger the same way. This is extending it to the icon as well.

Fixed the logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think my brain wasn't functioning last night when I wrote the logic for this. 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Using the selected icon if defined makes sense, but not using the component wide icon if the selections aren't individually... iconized breaks the original intent. I think it's just two different styles:
image

in this one, that icon just is meant to apply to every option, but not appear as a duplicate in the option list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

spectator.tick();

// No selection -> select component level icon and no color
expect(spectator.debugElement.query(By.css('.trigger-prefix-icon')).componentInstance.icon).toBe(
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason to use debug element querying rather than spectator querying ? is it because spectator doesn't give you access to the component on root queries?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep. wanted to access component to verify the contents of it.

'select-level-icon'
);
// tslint:disable-next-line:no-null-keyword
expect(spectator.debugElement.query(By.css('.trigger-prefix-icon')).componentInstance.color).toBe(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: toBeNull() (avoids the tslint disable)

@arjunlalb arjunlalb merged commit cc56d63 into main May 28, 2021
@arjunlalb arjunlalb deleted the update-select branch May 28, 2021 12:40
@github-actions
Copy link

Unit Test Results

    4 files  ±0  255 suites  ±0   15m 57s ⏱️ +45s
922 tests +1  922 ✔️ +1  0 💤 ±0  0 ❌ ±0 
928 runs  +1  928 ✔️ +1  0 💤 ±0  0 ❌ ±0 

Results for commit cc56d63. ± Comparison against base commit 7e0fa79.

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.

3 participants