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

feat: select header and footer #409

Closed
wants to merge 0 commits into from

Conversation

CO97
Copy link

@CO97 CO97 commented Nov 2, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Which package are you modifying?

  • accordion
  • alert
  • alert-dialog
  • aspect-ratio
  • avatar
  • badge
  • button
  • calendar
  • card
  • checkbox
  • collapsible
  • combobox
  • command
  • context-menu
  • data-table
  • date-picker
  • dialog
  • dropdown-menu
  • hover-card
  • icon
  • input
  • label
  • menubar
  • navigation-menu
  • pagination
  • popover
  • progress
  • radio-group
  • scroll-area
  • select
  • separator
  • sheet
  • skeleton
  • slider
  • sonner
  • spinner
  • switch
  • table
  • tabs
  • textarea
  • toast
  • toggle
  • tooltip
  • typography

What is the current behavior?

The current select implementation does not allow for fixed items to be added as a header or footer to the dropdown content.

Closes #400

What is the new behavior?

This change adds flexibility without changing the functionality or structure of the existing implementation by adding two new optional directives for projecting in content to the header/footer of the dropdown.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

A real world example of where this is useful is for a select all or reset buttons to be shown in the dropdown, another example is a count of available items vs selected items.

@CO97
Copy link
Author

CO97 commented Nov 2, 2024

Please let me know of any changes needed, this is my first time committing to an open source project and I am interested in contributing further to this one!

Copy link
Collaborator

@elite-benni elite-benni left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Would you be so kind and add an e2e test for the change?

Additionally this PR reveals an existing bug in the scrolling implementation.
I left a comment in the code.

Kind regards

Copy link
Collaborator

Choose a reason for hiding this comment

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

The scrolling to bottom does not work smoothly when there is a footer in place.
It is caused by the current implementation of the moveFocusDown(), which seems to use some hardcoded pixel values.
This would also not work if someone uses a different height for the scroll button, so technically this was already a bug.

Some quick tests with the following code seemed to fix this issue.

public moveFocusDown() {
	const nativeElement = this.viewport.nativeElement;
	nativeElement.scrollBy({ top: 100, behavior: 'smooth' });
	const { clientHeight, scrollHeight, scrollTop } = nativeElement;
	if (clientHeight + scrollTop >= scrollHeight) {
		this.scrollDownBtn.stopEmittingEvents();
	}
}

@thatsamsonkid
Copy link
Collaborator

One small concern I have is how this will behave from an Accessibility standpoint. Not sure how a screenreader would read content in this areas if it's not technically an option. Also i'm curious if this opens up the component to some kind of bad practice. Might be worth doing a manual spot check on this. Not saying we can't add but we might want to mention in docs that adding anything to complex in these areas might not be accessible or affect accessibility

@elite-benni
Copy link
Collaborator

One small concern I have is how this will behave from an Accessibility standpoint. Not sure how a screenreader would read content in this areas if it's not technically an option. Also i'm curious if this opens up the component to some kind of bad practice. Might be worth doing a manual spot check on this. Not saying we can't add but we might want to mention in docs that adding anything to complex in these areas might not be accessible or affect accessibility

good point!

@CO97
Copy link
Author

CO97 commented Nov 8, 2024

One small concern I have is how this will behave from an Accessibility standpoint. Not sure how a screenreader would read content in this areas if it's not technically an option. Also I'm curious if this opens up the component to some kind of bad practice. Might be worth doing a manual spot check on this. Not saying we can't add but we might want to mention in docs that adding anything to complex in these areas might not be accessible or affect accessibility

In regards to opening the component to bad practice, I would argue that we should leave it up to the developer on what content they want to display. A warning around it in the docs would be the best way to go.

@CO97
Copy link
Author

CO97 commented Nov 8, 2024

I have thought about this implementation further, the issue arises because of the content having the scrolling functionality built into the dropdown and this is more of a bandade than addressing the underlying issue. Would it be better to break out the scrollable area into a separate component that can be used or ignored if a developer wanted to use their own simple scroll with overflow y on the container?

It would allow total customization of the layout within the content. I would be interested to hear your opinions on this?

<brn-select class="inline-block" placeholder="Select an option">
      <hlm-select-trigger class="w-56">
        <hlm-select-value />
      </hlm-select-trigger>
      <hlm-select-content>
        <hlm-select-content-scroll> <-- New scroll component?
            <hlm-option value="Refresh">Refresh</hlm-option>
            <hlm-option value="Settings">Settings</hlm-option>
            <hlm-option value="Help">Help</hlm-option>
            <hlm-option value="Signout">Sign out</hlm-option>
        <hlm-select-content-scroll>
      </hlm-select-content>
    </brn-select>

Example with custom content;

<brn-select class="inline-block" placeholder="Select an option">
      <hlm-select-trigger class="w-56">
        <hlm-select-value />
      </hlm-select-trigger>
      <hlm-select-content>
        <span>Custom Content at Header</span>
        <hlm-select-content-scroll> <-- New scroll component?
            <hlm-option value="Refresh">Refresh</hlm-option>
            <hlm-option value="Settings">Settings</hlm-option>
            <hlm-option value="Help">Help</hlm-option>
            <hlm-option value="Signout">Sign out</hlm-option>
        <hlm-select-content-scroll>
         <span>Custom Content at Footer</span>
      </hlm-select-content>
    </brn-select>

@CO97 CO97 closed this Nov 11, 2024
@CO97 CO97 force-pushed the feat/select-header-and-footer branch from 102581d to f2f65c1 Compare November 11, 2024 00:25
@CO97 CO97 mentioned this pull request Nov 11, 2024
57 tasks
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.

Select Content - Allow items to be fixed at top or bottom outside of scrollable element.
3 participants