Skip to content

Commit

Permalink
[ToggleButton] Add prop types for onClick and onChange (mui#30883)
Browse files Browse the repository at this point in the history
Co-authored-by: siriwatknp <siriwatkunaporn@gmail.com>
  • Loading branch information
sydneyjodon-wk and siriwatknp authored Feb 14, 2022
1 parent cc09e65 commit d68201c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/pages/api-docs/toggle-button.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"disableFocusRipple": { "type": { "name": "bool" } },
"disableRipple": { "type": { "name": "bool" } },
"fullWidth": { "type": { "name": "bool" } },
"onChange": { "type": { "name": "func" } },
"onClick": { "type": { "name": "func" } },
"selected": { "type": { "name": "bool" } },
"size": {
"type": {
Expand Down
2 changes: 2 additions & 0 deletions docs/pages/material/api/toggle-button.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"disableFocusRipple": { "type": { "name": "bool" } },
"disableRipple": { "type": { "name": "bool" } },
"fullWidth": { "type": { "name": "bool" } },
"onChange": { "type": { "name": "func" } },
"onClick": { "type": { "name": "func" } },
"selected": { "type": { "name": "bool" } },
"size": {
"type": {
Expand Down
2 changes: 2 additions & 0 deletions docs/translations/api-docs/toggle-button/toggle-button.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"disableFocusRipple": "If <code>true</code>, the keyboard focus ripple is disabled.",
"disableRipple": "If <code>true</code>, the ripple effect is disabled.<br>⚠️ Without a ripple there is no styling for :focus-visible by default. Be sure to highlight the element by applying separate styles with the <code>.Mui-focusVisible</code> class.",
"fullWidth": "If <code>true</code>, the button will take up the full width of its container.",
"onChange": "Callback fired when the state changes.<br><br><strong>Signature:</strong><br><code>function(event: React.MouseEvent&lt;HTMLElement&gt;, value: any) =&gt; void</code><br><em>event:</em> The event source of the callback.<br><em>value:</em> of the selected button.",
"onClick": "Callback fired when the button is clicked.<br><br><strong>Signature:</strong><br><code>function(event: React.MouseEvent&lt;HTMLElement&gt;, value: any) =&gt; void</code><br><em>event:</em> The event source of the callback.<br><em>value:</em> of the selected button.",
"selected": "If <code>true</code>, the button is rendered in an active state.",
"size": "The size of the component. The prop defaults to the value inherited from the parent ToggleButtonGroup component.",
"sx": "The system prop that allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/the-sx-prop/\">`sx` page</a> for more details.",
Expand Down
15 changes: 15 additions & 0 deletions packages/mui-material/src/ToggleButton/ToggleButton.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SxProps } from '@mui/system';
import { OverridableStringUnion } from '@mui/types';
import * as React from 'react';
import { Theme } from '..';
import { ExtendButtonBase, ExtendButtonBaseTypeMap } from '../ButtonBase';
import { OverrideProps } from '../OverridableComponent';
Expand Down Expand Up @@ -45,6 +46,20 @@ export type ToggleButtonTypeMap<
* @default false
*/
fullWidth?: boolean;
/**
* Callback fired when the state changes.
*
* @param {React.MouseEvent<HTMLElement>} event The event source of the callback.
* @param {any} value of the selected button.
*/
onChange?: (event: React.MouseEvent<HTMLElement>, value: any) => void;
/**
* Callback fired when the button is clicked.
*
* @param {React.MouseEvent<HTMLElement>} event The event source of the callback.
* @param {any} value of the selected button.
*/
onClick?: (event: React.MouseEvent<HTMLElement>, value: any) => void;
/**
* If `true`, the button is rendered in an active state.
*/
Expand Down
10 changes: 8 additions & 2 deletions packages/mui-material/src/ToggleButton/ToggleButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,17 @@ ToggleButton.propTypes /* remove-proptypes */ = {
*/
fullWidth: PropTypes.bool,
/**
* @ignore
* Callback fired when the state changes.
*
* @param {React.MouseEvent<HTMLElement>} event The event source of the callback.
* @param {any} value of the selected button.
*/
onChange: PropTypes.func,
/**
* @ignore
* Callback fired when the button is clicked.
*
* @param {React.MouseEvent<HTMLElement>} event The event source of the callback.
* @param {any} value of the selected button.
*/
onClick: PropTypes.func,
/**
Expand Down
4 changes: 4 additions & 0 deletions packages/mui-material/src/ToggleButton/ToggleButton.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as React from 'react';
import ToggleButton from '@mui/material/ToggleButton';

<ToggleButton value="" onChange={(event, value: string) => {}} onClick={(event, value) => {}} />;

0 comments on commit d68201c

Please sign in to comment.