-
Notifications
You must be signed in to change notification settings - Fork 205
feat(search): collapsed search #4115
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
Changes from 3 commits
3472bc1
79e4fbe
da1426c
3579e94
324c916
db04073
e26ae55
9ae58b7
d466f99
57931fd
9324fdd
62498f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
"@spectrum-css/search": major | ||
--- | ||
|
||
## S2 Minimized search field | ||
|
||
The search component allows for a minimized state where the search field is collapsed to a button. | ||
|
||
### Anatomy | ||
|
||
The collapsed state consists of a single action button that only has a hover and disabled state. This state is triggered by the `is-collapsed` class on the search component. When the search field is in this state, the textfield is hidden and the search button is displayed. The button can be hovered and focused, and will expand the search field when clicked. | ||
|
||
### Usage | ||
|
||
The collapsed state is used to reduce the amount of space taken up by the search field. It is most commonly used next a filter button to allow users to quickly search and filter content. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,20 @@ | |
.spectrum-HelpText { | ||
margin-block-start: var(--mod-search-to-help-text, var(--spectrum-search-to-help-text)); | ||
} | ||
|
||
/* Animation for collapsible search expansion */ | ||
&.is-collapsed { | ||
transition: inline-size 0.3s cubic-bezier(0.4, 0, 0.2, 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how would you feel about maybe using of any of the Should the cubic-beziers and even the transition-duration be set as custom props? Maybe it's not necessary, but we do use the same curve & durations twice 🤷♀️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm just experimenting with animation curves here. I don't know what the intended animation should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh nice! I've been learning about each of the values of the |
||
inline-size: var(--mod-search-button-inline-size, var(--spectrum-search-block-size)); | ||
min-inline-size: var(--mod-search-button-inline-size, var(--spectrum-search-block-size)); | ||
transform-origin: left center; | ||
} | ||
|
||
&.is-expanded { | ||
transition: inline-size 0.3s cubic-bezier(0.4, 0, 0.2, 1); | ||
inline-size: var(--mod-search-inline-size, var(--spectrum-search-inline-size)); | ||
transform-origin: left center; | ||
} | ||
} | ||
|
||
.spectrum-Search-clearButton { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { Template as ActionButton } from "@spectrum-css/actionbutton/stories/template.js"; | ||
import { Template as ClearButton } from "@spectrum-css/clearbutton/stories/template.js"; | ||
import { Template as HelpText } from "@spectrum-css/helptext/stories/template.js"; | ||
import { Container } from "@spectrum-css/preview/decorators"; | ||
|
@@ -19,7 +20,9 @@ export const Template = ({ | |
size = "m", | ||
showHelpText = false, | ||
helpTextLabel = "", | ||
isCollapsed = false, | ||
} = {}, context = {}) => { | ||
const { updateArgs } = context; | ||
return html` | ||
<form | ||
class=${classMap({ | ||
|
@@ -28,38 +31,56 @@ export const Template = ({ | |
typeof size !== "undefined" && size !== "m", | ||
"is-disabled": isDisabled, | ||
"is-keyboardFocused": isKeyboardFocused, | ||
"is-collapsed": isCollapsed, | ||
"is-expanded": !isCollapsed, | ||
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}), | ||
})} | ||
aria-label="Search" | ||
> | ||
${TextField({ | ||
isDisabled, | ||
size, | ||
customClasses: [ | ||
`${rootClass}-textfield`, | ||
isFocused && "is-focused", | ||
isKeyboardFocused && "is-keyboardFocused", | ||
isHovered && "is-hover" | ||
], | ||
iconName: "Search", | ||
setName: "workflow", | ||
type: "search", | ||
placeholder: "Search", | ||
name: "search", | ||
customInputClasses: [`${rootClass}-input`], | ||
customIconClasses: [`${rootClass}-icon`], | ||
autocomplete: false, | ||
value: inputValue, | ||
}, context)} | ||
${when(inputValue, () => | ||
${when(isCollapsed, () => | ||
ActionButton({ | ||
iconName: "Search", | ||
size, | ||
customClasses: [ | ||
`${rootClass}-actionButton`, | ||
isHovered && "is-hover", | ||
isDisabled && "is-disabled", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My only suggestion is to make sure we can't keyboard focus to this button when it's disabled! ![]() I'm not sure if this is a property thing? It certainly looks like we're passing the disabled arg through correctly- I see it on the search AND on the action button, but maybe we need to revisit the disabled+keyboard focus styles. |
||
], | ||
onclick: () => { | ||
updateArgs({ isCollapsed: !isCollapsed }); | ||
}, | ||
}, context) | ||
)} | ||
${when(!isCollapsed, () => | ||
TextField({ | ||
isDisabled, | ||
size, | ||
customClasses: [ | ||
`${rootClass}-textfield`, | ||
isFocused && "is-focused", | ||
isKeyboardFocused && "is-keyboardFocused", | ||
isHovered && "is-hover" | ||
], | ||
iconName: "Search", | ||
setName: "workflow", | ||
type: "search", | ||
placeholder: "Search", | ||
name: "search", | ||
customInputClasses: [`${rootClass}-input`], | ||
customIconClasses: [`${rootClass}-icon`], | ||
autocomplete: false, | ||
value: inputValue, | ||
}, context) | ||
)} | ||
${when(inputValue && !isCollapsed, () => | ||
ClearButton({ | ||
isDisabled, | ||
size, | ||
customClasses: [`${rootClass}-clearButton`], | ||
isFocusable: false, | ||
}, context) | ||
)} | ||
${when(showHelpText, () => | ||
${when(showHelpText && !isCollapsed, () => | ||
HelpText({ | ||
text: helpTextLabel, | ||
size, | ||
|
Uh oh!
There was an error while loading. Please reload this page.