Skip to content

ref(compactSelect): Small improvements - #46642

Merged
vuluongj20 merged 3 commits into
masterfrom
vl/compact-select-improvement
Apr 3, 2023
Merged

ref(compactSelect): Small improvements#46642
vuluongj20 merged 3 commits into
masterfrom
vl/compact-select-improvement

Conversation

@vuluongj20

Copy link
Copy Markdown
Contributor

A few small improvements to CompactSelect. See comments for more details.

@vuluongj20
vuluongj20 requested a review from a team as a code owner March 30, 2023 22:08
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Mar 30, 2023
Comment on lines +250 to +255
// Focus on search box if present
if (searchable) {
searchRef.current?.focus();
return;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If present (searchable is true), the search box will receive focus when the menu opens. Otherwise, the list box will receive focus.

image

Comment on lines +351 to +355
const showClearButton = useMemo(
() => selectedOptions.flat().length > 0,
[selectedOptions]
);

@vuluongj20 vuluongj20 Mar 30, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The clear button will be hidden if no option has been selected:
image

Comment on lines +3 to +11
export interface SelectOption<Value extends React.Key> extends SelectValue<Value> {
/**
* Whether to hide the checkbox/checkmark. Available for backward compatibility only.
* If true, an alternative selection state indicator must be present.
*
* @deprecated
*/
hideCheck?: boolean;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is now possible to hide the leading checkbox. This feature was added specifically for page filters, which use a hybrid selection pattern.
image

The prop for this, hideCheck, is marked as deprecated to discourage further use. (If there's a better, more tailored way to restrict usage, pls tell me!).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, it's not ideal to say it's deprecated, as that implies we want to try to remove it.

@vuluongj20 vuluongj20 Mar 30, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I agree. Not sure what else to do though. @deprecation was a decent choice because VSCode will add a strikethrough over the name, so at least it'll grab people's attention when they try to use it.

I could also just add a warning in all caps in the prop description, but there's a much lower chance of people seeing it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Lol I tagged an org called Deprecation trying to write @deprecation

: listState.selectionManager.selectionMode === 'multiple';

const {rowProps, gridCellProps, isSelected, isDisabled} = useGridListItem(
const {rowProps, gridCellProps, isSelected, isDisabled, isPressed} = useGridListItem(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Using react-aria's isPressed prop to track press states (the value is passed to InteractionStateLayer). This is better because the :active pseudo-class is activated even when the user presses on a child interactive element.

Before —— pressing on the bookmark star activates the whole option's press state, which is confusing because it suggests that the option will be selected (it won't)
image

After —— pressing the bookmark star doesn't trigger the option's press state
image

Comment on lines +120 to +125

li[role="rowgroup"]:hover &,
li[role="presentation"]:hover & {
opacity: 1;
pointer-events: all;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Section toggle buttons ("Select All") will show up when hovering over the section, including the section header.
image

Before, the buttons will only show up if one of the section's options have focus.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also I would be OKAY if we changed he UI for this and moved the checks to the left

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Decided to keep the checkboxes on the right side because of the page filters' weird hybrid selection mode. Here, the primary selection mode is singular. It's only when you click on the checkbox that the secondary selection mode — multiple — applies.
Having the checkbox on the right, trailing side works better, I think, because that's where we put secondary actions. Putting it in the left, leading side might confuse the user into thinking that the primary selection mode is multiple.

@vuluongj20
vuluongj20 requested review from a team and removed request for a team March 31, 2023 22:55
Comment on lines -62 to +72
export interface ControlProps extends UseOverlayProps {
export interface ControlProps
extends Omit<
React.BaseHTMLAttributes<HTMLDivElement>,
// omit keys from SingleListProps because those will be passed to <List /> instead
keyof Omit<
SingleListProps<React.Key>,
'children' | 'items' | 'grid' | 'compositeIndex' | 'label'
>
>,
UseOverlayProps {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Adding React.BaseHTMLAttributes<HTMLDivElement> so we can attach HTML props, like onKeyDown, to CompactSelect. These props will be passed to the ControlWrap element.

@vuluongj20
vuluongj20 merged commit 4b02523 into master Apr 3, 2023
@vuluongj20
vuluongj20 deleted the vl/compact-select-improvement branch April 3, 2023 18:52
vuluongj20 added a commit that referenced this pull request Apr 3, 2023
Fix `CompactSelect` tests that failed when
#46642 was merged.
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants