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(search): add support for expandable variant #8101

Merged
merged 10 commits into from
Apr 10, 2021

Conversation

janhassel
Copy link
Member

Closes #6360

Adds an expandable variant to the search component.

Changelog

New

  • Expandable variant / kind for search component

Changed

  • Renamed previous bx--search-magnifier classname to bx--search-magnifier-icon
    • If changing classnames is considered a breaking change, I can also revert this and change the new bx--search-magnifier to bx--search-magnifier-container – just let me know!
  • Updated API snapshot to reflect new prop

Testing / Reviewing

When props.kind = 'expandable', the search component should

  • be collapsed by default
  • open by either
    • clicking the search icon
    • tabbing into it / receiving focus
  • close when it loses focus and has no content
  • stay open if it loses focus and has content

@janhassel janhassel requested review from a team as code owners March 16, 2021 15:38
@janhassel janhassel requested review from joshblack and dakahn March 16, 2021 15:38
@netlify
Copy link

netlify bot commented Mar 16, 2021

Deploy preview for carbon-elements ready!

Built with commit f442072

https://deploy-preview-8101--carbon-elements.netlify.app

@netlify
Copy link

netlify bot commented Mar 16, 2021

Deploy preview for carbon-components-react ready!

Built without sensitive environment variables with commit f442072

https://deploy-preview-8101--carbon-components-react.netlify.app

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

The alignment is off in DataTable in the button/hover icon alignment, the alignment of the button when it's expanded, and the interior left padding of the input when expanded.

search alignment

Comment on lines +304 to +308
width: 0;
padding: 0;
transition-timing-function: motion(standard, productive);
transition-duration: $duration--fast-01;
transition-property: width, padding;
Copy link
Member

Choose a reason for hiding this comment

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

Cool, so it looks like this will inherently support animating leftwards, rightwards, or both from the center 👍

/**
* Optional prop to specify the kind of this component
*/
kind: PropTypes.oneOf(['default', 'expandable']),
Copy link
Contributor

Choose a reason for hiding this comment

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

One quick question, curious what you think between using kind props versus named variants of a component.

e.g. we have <Search kind="expandable" /> or <ExpandableSearch />

I've definitely leaned towards the latter since the kind prop makes it harder to group related functionality around a variant but I'm super curious what you think @janhassel

Copy link
Collaborator

@tw15egan tw15egan Mar 22, 2021

Choose a reason for hiding this comment

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

Could the prop name also be something like isExpandable?

Or we could mimic the TableToolbarSearch prop, and use persistent and default that to true? (perhaps renamed in both places to isPersistent in v11)

Copy link
Member Author

Choose a reason for hiding this comment

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

I initially thought this variant would not be big enough to make into its own component but after looking further into some other components, maybe the guidance could be to use kind whenever the appearance is the main differentiator and creating a new component whenever the behaviour is affected. In that case, this should be an <ExpandableSearch /> as @joshblack mentioned.

This is based on the following:

Component kind wrapper Effect
Button X Changes appearance: primary, secondary, ghost, danger
Notification X Changes apperance: success, error, warning, information
Tile X Changes behaviour: ClickableTile, SelectableTile, RadioTile
ContextMenu X Changes behaviour: ContextMenuItem, ContextMenuSelectableItem, ContextMenu

The (somewhat) recent change in Toggle / ToggleSmall also reflects this rule: #7380

Let me know what you think about this approach and I'll update the PR accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

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

@janhassel that's a great breakdown. When the prop controls behavior (or even something like markup potentially) the wrapper approach works great. If it's a visual change only (like classes) then inlining in the component makes more sense.

Following that chart, does it make sense for ExpandableSearch to be a wrapper, or am I misunderstanding? 👀

Copy link
Member Author

Choose a reason for hiding this comment

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

@joshblack Yes, I'd say this should be a wrapper component called ExpandableSearch following above's approach. If you agree, @tw15egan then I'll go ahead and update the PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's do it! 👍🏻

Copy link
Member Author

Choose a reason for hiding this comment

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

@joshblack @tw15egan Just pushed an update. I tried syncing the prop types with ExpandableSearch.propTypes = Search.propTypes which seems to work fine for validation but the storybook docs don't pick them up. Do you guys have any idea on how to solve this?

@janhassel
Copy link
Member Author

@tay1orjones Good catch! This was caused by the change class name change. Just pushed an update!

@dakahn
Copy link
Contributor

dakahn commented Mar 30, 2021

@carbon-design-system/design just wanted to tap yall in for a sign off here
This PR adds a collapsible global search variant like the search seen in DataTable (where it expands from just a magnifying icon).

Specifically want to call attention to the animation behavior where the search expands on focus -- which seems different than what we do on carbondesignsystem.com (expand on focus is better 👍🏽)

@dakahn dakahn removed their request for review April 5, 2021 22:50
@tw15egan tw15egan requested a review from laurenmrice April 6, 2021 16:59
Copy link
Member

@laurenmrice laurenmrice left a comment

Choose a reason for hiding this comment

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

  • In Safari: The word Search is persistent by default next to the search icon. It should only be the icon.

Screen Shot 2021-04-06 at 4 57 52 PM

@janhassel
Copy link
Member Author

@laurenmrice Should be fixed now!

@janhassel janhassel requested a review from laurenmrice April 7, 2021 07:56
Copy link
Member

@laurenmrice laurenmrice left a comment

Choose a reason for hiding this comment

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

looks good 👍

Copy link
Contributor

@joshblack joshblack left a comment

Choose a reason for hiding this comment

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

Looking great!

@joshblack
Copy link
Contributor

bump @tay1orjones @tw15egan when you have a sec to re-review 👀

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

Sorry, thought I had already put an approve on here.

The storybook prop table is a bummer but I don't think there's a workaround since it's probably blowing up react-docgen. The easiest way I know of to fix is to just copy/paste the proptypes 😞

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

Successfully merging this pull request may close these issues.

[Search] Add support for expandable kind
6 participants