Skip to content

Commit

Permalink
make clear selection optional
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthkp committed Sep 13, 2023
1 parent 2446735 commit b6ff7f9
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/drafts/SelectPanel2/SelectPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ import {
import {useSlots} from '../../hooks/useSlots'
import {ClearIcon} from './tmp-ClearIcon'

const SelectPanelContext = React.createContext({
const SelectPanelContext = React.createContext<{
onCancel: () => void
onClearSelection: undefined | (() => void)
searchQuery: string
setSearchQuery: () => void
}>({
onCancel: () => {},
onClearSelection: () => {},
onClearSelection: undefined,
searchQuery: '',
setSearchQuery: () => {},
})
Expand Down Expand Up @@ -82,7 +87,7 @@ const SelectPanel = props => {
<SelectPanelContext.Provider
value={{
onCancel: onInternalClose,
onClearSelection: onInternalClearSelection,
onClearSelection: props.onClearSelection ? onInternalClearSelection : undefined,
searchQuery,
// @ts-ignore todo
setSearchQuery,
Expand Down Expand Up @@ -117,9 +122,11 @@ const SelectPanelHeader: React.FC<React.PropsWithChildren> = ({children, ...prop
{slots.heading}
<Box>
{/* Will not need tooltip after https://github.com/primer/react/issues/2008 */}
<Tooltip text="Clear selection" direction="s" onClick={onClearSelection}>
<IconButton type="button" variant="invisible" icon={ClearIcon} aria-label="Clear selection" />
</Tooltip>
{onClearSelection ? (
<Tooltip text="Clear selection" direction="s" onClick={onClearSelection}>
<IconButton type="button" variant="invisible" icon={ClearIcon} aria-label="Clear selection" />
</Tooltip>
) : null}
<Tooltip text="Close" direction="s">
<IconButton type="button" variant="invisible" icon={XIcon} aria-label="Close" onClick={() => onCancel()} />
</Tooltip>
Expand Down

0 comments on commit b6ff7f9

Please sign in to comment.