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

fix: ComboBoxInput.tsx uses chips only if multiselect #1029

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function Pagination(props: PaginationProps) {
<div css={Css.df.mya.mr2.$} {...tid.pageSizeLabel}>
Page size:
</div>
<div css={Css.wPx(95).$}>
<div css={Css.wPx(78).$}>
bdow marked this conversation as resolved.
Show resolved Hide resolved
<SelectField
compact
label="Page Size"
Expand Down
7 changes: 3 additions & 4 deletions src/inputs/internal/ComboBoxInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { ComboBoxState } from "react-stately";
import { Chips, Icon, Tooltip } from "src/components";
import { PresentationFieldProps, usePresentationContext } from "src/components/PresentationContext";
import { Css } from "src/Css";
import { useGrowingTextField } from "src/inputs/hooks/useGrowingTextField";
import { TextFieldBase } from "src/inputs/TextFieldBase";
import { useTreeSelectFieldProvider } from "src/inputs/TreeSelectField/TreeSelectField";
import { isLeveledNode } from "src/inputs/TreeSelectField/utils";
Expand Down Expand Up @@ -85,8 +84,8 @@ export function ComboBoxInput<O, V extends Value>(props: ComboBoxInputProps<O, V
const [isFocused, setIsFocused] = useState(false);
const isMultiSelect = state.selectionManager.selectionMode === "multiple";
const showNumSelection = isMultiSelect && state.selectionManager.selectedKeys.size > 1;
// Show selections as chips
const hasSelection = state.selectionManager.selectedKeys.size > 0;
// Show selections as chips when using multiselect when unfocused
const showChipSelection = isMultiSelect && state.selectionManager.selectedKeys.size > 0;
// For MultiSelect only show the `fieldDecoration` when input is not in focus.
const showFieldDecoration =
(!isMultiSelect || (isMultiSelect && !isFocused)) && fieldDecoration && selectedOptions.length === 1;
Expand All @@ -99,7 +98,7 @@ export function ComboBoxInput<O, V extends Value>(props: ComboBoxInputProps<O, V
<TextFieldBase
{...otherProps}
{...multilineProps}
unfocusedPlaceholder={hasSelection && <Chips compact={otherProps.compact} values={chipLabels} />}
unfocusedPlaceholder={showChipSelection && <Chips compact={otherProps.compact} values={chipLabels} />}
inputRef={inputRef}
inputWrapRef={inputWrapRef}
errorMsg={errorMsg}
Expand Down
Loading