diff --git a/docs/pages/x/api/date-pickers/pickers-shortcuts.json b/docs/pages/x/api/date-pickers/pickers-shortcuts.json index dd402f9066e1..62d701e3e1cf 100644 --- a/docs/pages/x/api/date-pickers/pickers-shortcuts.json +++ b/docs/pages/x/api/date-pickers/pickers-shortcuts.json @@ -9,7 +9,7 @@ "items": { "type": { "name": "arrayOf", - "description": "Array<{ getValue: func, label: string }>" + "description": "Array<{ getValue: func, key?: string, label: string }>" }, "default": "[]" }, diff --git a/packages/x-date-pickers/src/PickersShortcuts/PickersShortcuts.tsx b/packages/x-date-pickers/src/PickersShortcuts/PickersShortcuts.tsx index 85d88255963b..8e36ecf55245 100644 --- a/packages/x-date-pickers/src/PickersShortcuts/PickersShortcuts.tsx +++ b/packages/x-date-pickers/src/PickersShortcuts/PickersShortcuts.tsx @@ -12,6 +12,7 @@ interface PickersShortcutsItemGetValueParams { export interface PickersShortcutsItem { label: string; getValue: (params: PickersShortcutsItemGetValueParams) => TValue; + key?: string; } export type PickersShortcutsItemContext = Omit, 'getValue'>; @@ -64,6 +65,7 @@ function PickersShortcuts(props: PickersShortcutsProps) { const newValue = getValue({ isValid }); return { + key: item?.key || item.label, label: item.label, onClick: () => { onChange(newValue, changeImportance, item); @@ -132,6 +134,7 @@ PickersShortcuts.propTypes = { items: PropTypes.arrayOf( PropTypes.shape({ getValue: PropTypes.func.isRequired, + key: PropTypes.string, label: PropTypes.string.isRequired, }), ),