Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Datagrid filter setFocus #542

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

irahov
Copy link
Contributor

@irahov irahov commented Nov 27, 2023

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Examples have been added / updated (for bug fixes / features)
  • Changelog has been updated

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
  • Example website changes
  • Version bump
  • Other... Please describe:

What does this change do?

When opening a datagrid filter the focus should go directly to the relevant HTML element so that the user can start filtering right away.
Up to now the focus was on the flter close button 'X'. This is extremely boring when using string filter because the user has to click first on the input field (or TAB to it) and then start writing.

What manual testing did you do?

In the example applications navigate to Datagrid -> Datagrid Filters (/datagrid/example/datagrid-filter)
Open each of the filters and verify that the focus is on the input field or the select .

Screenshots (if applicable)

Does this PR introduce a breaking change?

  • Yes
  • No

Breaking changes need:

  • removing modifier for ClrDatagridFilter parameter of the child constructor, i.e. it should be filterContainer: ClrDatagridFilter only
  • implement setFocus() method on the child class

Other information

Ivo Rahov added 2 commits November 27, 2023 13:43
The property `filterContainer` is used by the subclasses
and is gonna be needed for this base class also so we make
it protected.

Signed-off-by: Ivo Rahov <[email protected]>
Changes include:
- added abstract method setFocus
-added implementation for the different filters to set focus

Signed-off-by: Ivo Rahov <[email protected]>
@@ -127,6 +127,10 @@ export class DatagridMultiSelectFilterComponent extends DatagridFilter<string[],
!!Object.keys(this.formGroup.getRawValue()).filter((frmCtrl) => this.formGroup.get(frmCtrl).value).length
);
}

protected setFocus() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a better approach is to have a method called getFocusableElement(), then the callers just have to return the element instead of every implementation calling focus().

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 like the focus() since it seems a more complete approach to me.
If I come accross to getFocusableElement() function - it is not that clear how the returned element will be used. Yes, the name suggests to focus, but yet - not that clean. In addition, I'm not sure if there is a case when something else may be needed when focusing the element. On the other hand focus() is more concise and clear.

I agree that the very .focus() call can be reused in the base class but I don't see it has the advantages as the other approach.

protected constructor(filterContainer: ClrDatagridFilter, private subscriptionTracker: SubscriptionTracker) {
protected constructor(
protected filterContainer: ClrDatagridFilter,
private subscriptionTracker: SubscriptionTracker
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're touching this file, we may as well remove the providers from here since it doesn't have any effect, the concrete classes need to add the providers.

Copy link
Contributor

Choose a reason for hiding this comment

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

@kepelrs discovered this while analyzing the SubscriptionTracker

Copy link

Choose a reason for hiding this comment

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

IIRC it was @irahov who discovered it first :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants