Skip to content

Commit

Permalink
chore: change prop onSelectionChange to onChange for select component (
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahgm committed Jan 31, 2023
1 parent 1f33094 commit 9cb030c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .changeset/seven-moose-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@marigold/docs": patch
"@marigold/components": major
---

chore: change prop onSelectionChange to onChange for select component
2 changes: 1 addition & 1 deletion docs/src/demos/components/Table/core-table-print.demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export const CorePrintTable = () => {
label="Sammelaktion"
placeholder="Bitte wählen"
width="unset"
onSelectionChange={handleSelect}
onChange={handleSelect}
>
<Select.Option key="choose">Bitte wählen</Select.Option>
<Select.Option key="ticketprint">Ticket drucken</Select.Option>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/select.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ import { Select } from '@marigold/components';
default: '100%',
},
{
property: 'onSelectionChange',
property: 'onChange',
type: '(key: Key) => any',
description: 'Handler that is called when the selection changes.',
default: 'none',
Expand Down
6 changes: 1 addition & 5 deletions packages/components/src/Select/Select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ export const Basic: ComponentStory<typeof Select> = args => {
const [selected, setSelected] = useState<string | number>('');
return (
<Container size="small">
<Select
{...args}
onSelectionChange={setSelected}
disabledKeys={['Firefly']}
>
<Select {...args} onChange={setSelected} disabledKeys={['Firefly']}>
<Select.Option key="Harry Potter">Harry Potter</Select.Option>
<Select.Option key="Lord of the Rings">Lord of the Rings</Select.Option>
<Select.Option key="Star Wars">Star Wars</Select.Option>
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/Select/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ test('controlled', () => {
render(
<OverlayProvider>
<ThemeProvider theme={theme}>
<Select label="Label" data-testid="select" onSelectionChange={spy}>
<Select label="Label" data-testid="select" onChange={spy}>
<Select.Option key="one">one</Select.Option>
<Select.Option key="two">two</Select.Option>
<Select.Option key="three">three</Select.Option>
Expand Down
26 changes: 24 additions & 2 deletions packages/components/src/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,17 @@ export interface SelectProps
| 'isDisabled'
| 'isRequired'
| 'validationState'
| 'onSelectionChange'
>,
Omit<
ComponentProps<'select'>,
'onKeyUp' | 'onKeyDown' | 'onFocus' | 'onBlur' | 'children' | 'size'
| 'onKeyUp'
| 'onKeyDown'
| 'onFocus'
| 'onBlur'
| 'children'
| 'size'
| 'onChange'
> {
variant?: string;
size?: string;
Expand All @@ -76,12 +83,26 @@ export interface SelectProps
disabled?: boolean;
required?: boolean;
error?: boolean;
onChange?: AriaSelectProps<object>['onSelectionChange'];
}

// Component
// ---------------
export const Select = forwardRef<HTMLButtonElement, SelectProps>(
({ variant, size, width, open, disabled, required, error, ...rest }, ref) => {
(
{
variant,
size,
width,
open,
disabled,
required,
error,
onChange,
...rest
},
ref
) => {
// Set up i18n
const formatMessage = useLocalizedStringFormatter(messages);

Expand All @@ -91,6 +112,7 @@ export const Select = forwardRef<HTMLButtonElement, SelectProps>(
isRequired: required,
validationState: error ? 'invalid' : 'valid',
placeholder: rest.placeholder || formatMessage.format('placeholder'),
onSelectionChange: onChange,
...rest,
} as const;

Expand Down

0 comments on commit 9cb030c

Please sign in to comment.