Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
8 changes: 7 additions & 1 deletion code/core/src/components/components/Select/Select.tsx
Copy link
Member

Choose a reason for hiding this comment

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

We'll need new stories showing how labels behave on !multiSelect and on multiSelect Selects, when a selection is made, and the option is on or off (so, 4 stories with defaultOptions and a play function validating the HTML output).

Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ export interface SelectProps
onSelect?: (option: Value) => void;
onDeselect?: (option: Value) => void;
onChange?: (selected: Value[]) => void;
/**
* Show the selected option's title in place of the children when an option is selected.
* Defaults to true.
*/
showSelectedLabel?: boolean;
}

function valueToId(parentId: string, { value }: InternalOption | ResetOption): string {
Expand Down Expand Up @@ -200,6 +205,7 @@ export const Select = forwardRef<HTMLButtonElement, SelectProps>(
onChange,
tooltip,
ariaLabel,
showSelectedLabel = true,
...props
},
ref
Expand Down Expand Up @@ -501,7 +507,7 @@ export const Select = forwardRef<HTMLButtonElement, SelectProps>(
{!multiSelect && (
<>
{icon}
{selectedOptions[0]?.title ?? children}
{(showSelectedLabel && selectedOptions[0]?.title) || children}
</>
)}

Expand Down
1 change: 1 addition & 0 deletions code/core/src/toolbar/components/ToolbarMenuSelect.tsx
Copy link
Member

Choose a reason for hiding this comment

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

Bunch more things to tidy up:

  • In docs/_snippets/storybook-preview-configure-globaltypes.md, could you please replace the 4 occurences of // Change title based on selected value to // Change title based on selected value (recommended for consistency with the Storybook UI)
  • Remove getSelectedTitle's source code as it is no longer needed

Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const ToolbarMenuSelect: FC<ToolbarMenuSelectProps> = withKeyboardCycle(
onReset={() => updateGlobals({ [id]: '_reset' })}
onSelect={(selected) => updateGlobals({ [id]: selected })}
icon={icon && <Icons icon={icon} __suppressDeprecationWarning={true} />}
showSelectedLabel={false}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
showSelectedLabel={false}
showSelectedLabel={dynamicTitle}

otherwise it'll never update

>
{title}
</Select>
Expand Down
Loading