-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Structure and slots for SearchBox, using Input as a slot #28090
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
Merged
smhigley
merged 36 commits into
microsoft:master
from
emmayjiang:react-search-create-SearchBox-slots
Jun 15, 2023
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
4b9205e
add slots and types for SearchBox
emmayjiang 1182bf3
fixing react-input version
emmayjiang 790194f
updating yarn.lock
emmayjiang 3ba7f4d
reorganizing code + alphabetizing package.json
emmayjiang 9dfa1e6
add slots and types for SearchBox
emmayjiang 536871b
fixing react-input version
emmayjiang 208d14a
updating yarn.lock
emmayjiang a2132e7
reorganizing code + alphabetizing package.json
emmayjiang 1abcf33
fix type errors
emmayjiang 9e04463
fix merge conflicts
emmayjiang 7c46d96
rebuild
emmayjiang 1d7698f
styles
emmayjiang b01fb29
remove pseudoelements from input
emmayjiang 3f46b1f
dismiss button functionality
emmayjiang d002d4d
packages
emmayjiang 0b33d33
fixes to dismiss button
emmayjiang c11417b
code revisions following sarah's feedback
emmayjiang 12f9886
styling issues
emmayjiang 881eff8
remove contentBefore slot
emmayjiang c09bc34
type fixes & handling custom dismiss callback
emmayjiang fb5fd63
api update
emmayjiang 96824e7
Merge branch 'master' into react-search-create-SearchBox-slots
emmayjiang 525e629
minor nits
emmayjiang 5dac8e5
refactor 'disabled'
emmayjiang 5008246
api update
emmayjiang 024eb53
Update packages/react-components/react-search/src/components/SearchBo…
emmayjiang 713dd7a
api update
emmayjiang 94e109d
api update
emmayjiang 0b654c3
Merge branch 'master' into react-search-create-SearchBox-slots
emmayjiang 8aa06b5
fixing styles errors
emmayjiang 3d66691
update react-icons version
emmayjiang 6a51ee8
fixes to ref + default
emmayjiang 1aace49
fix to ref
emmayjiang d571f62
api update
emmayjiang c04b6d7
fix tests
emmayjiang e9e42db
api update
emmayjiang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 13 additions & 5 deletions
18
packages/react-components/react-search/src/components/SearchBox/SearchBox.types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,25 @@ | ||
| import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
| import { Input, InputState } from '@fluentui/react-input'; | ||
|
|
||
| export type SearchBoxSlots = { | ||
| root: Slot<'div'>; | ||
| // Root of the component, wrapping the inputs | ||
| root: NonNullable<Slot<typeof Input>>; | ||
|
|
||
| // Last element in the input, within the input border | ||
| dismiss?: Slot<'span'>; | ||
|
|
||
| // Element after the input text, within the input border | ||
| contentAfter?: Slot<'span'>; | ||
| }; | ||
|
|
||
| /** | ||
| * SearchBox Props | ||
| */ | ||
| export type SearchBoxProps = ComponentProps<SearchBoxSlots> & {}; | ||
| export type SearchBoxProps = ComponentProps<SearchBoxSlots>; | ||
|
|
||
| /** | ||
| * State used in rendering SearchBox | ||
| */ | ||
| export type SearchBoxState = ComponentState<SearchBoxSlots>; | ||
| // TODO: Remove semicolon from previous line, uncomment next line, and provide union of props to pick from SearchBoxProps. | ||
| // & Required<Pick<SearchBoxProps, 'propName'>> | ||
| export type SearchBoxState = ComponentState<SearchBoxSlots> & | ||
| Required<Pick<InputState, 'size'>> & | ||
| Required<Pick<SearchBoxProps, 'disabled'>>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
packages/react-components/react-search/src/components/SearchBox/useSearchBox.ts
This file was deleted.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
packages/react-components/react-search/src/components/SearchBox/useSearchBox.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import * as React from 'react'; | ||
| import { mergeCallbacks, resolveShorthand, useControllableState, useEventCallback } from '@fluentui/react-utilities'; | ||
| import { Input } from '@fluentui/react-input'; | ||
| import type { SearchBoxProps, SearchBoxState } from './SearchBox.types'; | ||
| import { DismissRegular, SearchRegular } from '@fluentui/react-icons'; | ||
|
|
||
| /** | ||
| * Create the state required to render SearchBox. | ||
| * | ||
| * The returned state can be modified with hooks such as useSearchBoxStyles_unstable, | ||
| * before being passed to renderSearchBox_unstable. | ||
| * | ||
| * @param props - props from this instance of SearchBox | ||
| * @param ref - reference to root HTMLElement of SearchBox | ||
| */ | ||
| export const useSearchBox_unstable = (props: SearchBoxProps, ref: React.Ref<HTMLInputElement>): SearchBoxState => { | ||
| const { size = 'medium', disabled = false, contentBefore, dismiss, contentAfter, ...inputProps } = props; | ||
|
|
||
| const [value, setValue] = useControllableState({ | ||
| state: props.value, | ||
| defaultState: props.defaultValue, | ||
| initialState: '', | ||
| }); | ||
|
|
||
| const state: SearchBoxState = { | ||
| components: { | ||
| root: Input, | ||
| dismiss: 'span', | ||
| contentAfter: 'span', | ||
| }, | ||
|
|
||
| root: { | ||
| ref, | ||
| type: 'search', | ||
| input: {}, // defining here to have access in styles hook | ||
| value, | ||
|
|
||
| contentBefore: resolveShorthand(contentBefore, { | ||
| defaultProps: { | ||
| children: <SearchRegular />, | ||
| }, | ||
| required: true, // TODO need to allow users to remove | ||
| }), | ||
|
|
||
| ...inputProps, | ||
|
|
||
| onChange: useEventCallback(ev => { | ||
| const newValue = ev.target.value; | ||
| props.onChange?.(ev, { value: newValue }); | ||
| setValue(newValue); | ||
| }), | ||
emmayjiang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| dismiss: resolveShorthand(dismiss, { | ||
| defaultProps: { | ||
| children: <DismissRegular />, | ||
| role: 'button', | ||
| 'aria-label': 'clear', | ||
| }, | ||
| required: true, | ||
| }), | ||
| contentAfter: resolveShorthand(contentAfter, { required: true }), | ||
|
|
||
| disabled, | ||
| size, | ||
| }; | ||
|
|
||
| const onDismissClick = useEventCallback(mergeCallbacks(state.dismiss?.onClick, () => setValue(''))); | ||
| if (state.dismiss) { | ||
| state.dismiss.onClick = onDismissClick; | ||
| } | ||
|
|
||
| return state; | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.