Skip to content

Commit

Permalink
fix(control): expose event in case the user wants to stopPropagation
Browse files Browse the repository at this point in the history
  • Loading branch information
ritz078 committed Aug 28, 2018
1 parent 6fa8e2a commit b932139
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/components/CheckboxGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { getSelectedCheckboxes } from "./utils/getSelectedCheckboxes";
export default class RadioGroup extends React.PureComponent<
CheckboxGroupProps
> {
private handleChange = ({ value }) => {
private handleChange = ({ value }, event: React.MouseEvent) => {
const { onChange, selected } = this.props;
onChange(getSelectedCheckboxes(value, selected), this.props);
onChange(getSelectedCheckboxes(value, selected), event);
};

render() {
Expand Down
4 changes: 2 additions & 2 deletions src/components/RadioGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { RadioProps } from "./typings/Radio";
import { RadioGroupProps } from "./typings/RadioGroup";

export default class RadioGroup extends React.PureComponent<RadioGroupProps> {
private handleChange = ({ value, checked }) => {
private handleChange = ({ value, checked }, event: React.MouseEvent) => {
const { toggle, selected, onChange } = this.props;
if (!toggle && value === selected) return;
onChange(checked ? value : undefined, this.props);
onChange(checked ? value : undefined, event);
};

render() {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ const Select: React.SFC<SelectProps> = props => {
<React.Fragment>
<OptionGroup
selected={selected}
onChange={_value => {
onChange(_value, props);
onChange={(_value, event) => {
onChange(_value, event);
if (!multiSelect) {
toggle();
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/shared/Control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const Control: React.SFC<ControlProps> = props => {
data-disabled={disabled}
tabIndex={checked ? 0 : -1}
onClick={
!disabled ? () => onChange({ value, checked: !checked }) : undefined
!disabled
? (e: React.MouseEvent) => onChange({ value, checked: !checked }, e)
: undefined
}
>
{children(props)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/typings/CheckboxGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";

export interface CheckboxGroupProps {
selected: (number | string)[];
onChange: (value: (number | string)[], props: CheckboxGroupProps) => void;
onChange: (value: (number | string)[], e: React.MouseEvent) => void;
children: React.ReactNode | React.ReactNodeArray;
className?: string;
name: string;
Expand Down
5 changes: 4 additions & 1 deletion src/components/typings/Control.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import * as React from "react";

export interface ControlProps {
onChange?: (args: { value: React.ReactText; checked: boolean }) => void;
onChange?: (
args: { value: React.ReactText; checked: boolean },
e: React.MouseEvent
) => void;
value: React.ReactText;
label: string;
checked?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/components/typings/RadioGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";

export interface RadioGroupProps {
selected: number | string;
onChange: (value: number | string, props: RadioGroupProps) => void;
onChange: (value: number | string, event: React.MouseEvent) => void;
children: React.ReactNode | React.ReactNodeArray;
toggle?: boolean;
className?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/components/typings/Select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface SelectProps {
value?: string;
selected?: Selected;
multiSelect?: boolean;
onChange: (value: Selected, props: SelectProps) => void;
onChange: (value: Selected, event: React.MouseEvent) => void;
onApply?: (value: Selected, props: SelectProps) => void;
onClear?: () => void;
searchBox?: boolean;
Expand Down

0 comments on commit b932139

Please sign in to comment.