-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: MenuList props should win over context props (#26252)
* fix: MenuList props should win over context props Fixes the regression introduced in #25672 so that prop values win over context props with the same name. Fixes # * changefile
- Loading branch information
Showing
12 changed files
with
342 additions
and
26 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-menu-7ad515c7-ae51-477d-9289-c01f7a691b06.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "fix: MenuList props should win over context props", | ||
"packageName": "@fluentui/react-menu", | ||
"email": "lingfangao@hotmail.com", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/react-components/react-menu/stories/MenuList/MenuListCheckboxItems.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as React from 'react'; | ||
|
||
import { MenuList, MenuItemCheckbox, makeStyles, tokens } from '@fluentui/react-components'; | ||
import { | ||
bundleIcon, | ||
CutRegular, | ||
CutFilled, | ||
ClipboardPasteRegular, | ||
ClipboardPasteFilled, | ||
EditRegular, | ||
EditFilled, | ||
} from '@fluentui/react-icons'; | ||
|
||
const CutIcon = bundleIcon(CutFilled, CutRegular); | ||
const PasteIcon = bundleIcon(ClipboardPasteFilled, ClipboardPasteRegular); | ||
const EditIcon = bundleIcon(EditFilled, EditRegular); | ||
|
||
export const useMenuListContainerStyles = makeStyles({ | ||
container: { | ||
backgroundColor: tokens.colorNeutralBackground1, | ||
minWidth: '128px', | ||
minHeight: '48px', | ||
maxWidth: '300px', | ||
width: 'max-content', | ||
boxShadow: `${tokens.shadow16}`, | ||
paddingTop: '4px', | ||
paddingBottom: '4px', | ||
}, | ||
}); | ||
|
||
export const CheckboxItems = () => { | ||
const styles = useMenuListContainerStyles(); | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<MenuList> | ||
<MenuItemCheckbox icon={<CutIcon />} name="edit" value="cut"> | ||
Cut | ||
</MenuItemCheckbox> | ||
<MenuItemCheckbox icon={<PasteIcon />} name="edit" value="paste"> | ||
Paste | ||
</MenuItemCheckbox> | ||
<MenuItemCheckbox icon={<EditIcon />} name="edit" value="edit"> | ||
Edit | ||
</MenuItemCheckbox> | ||
</MenuList> | ||
</div> | ||
); | ||
}; |
56 changes: 56 additions & 0 deletions
56
.../react-components/react-menu/stories/MenuList/MenuListControlledCheckboxItems.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as React from 'react'; | ||
|
||
import { MenuList, MenuItemCheckbox, makeStyles, tokens } from '@fluentui/react-components'; | ||
import { | ||
bundleIcon, | ||
CutRegular, | ||
CutFilled, | ||
ClipboardPasteRegular, | ||
ClipboardPasteFilled, | ||
EditRegular, | ||
EditFilled, | ||
} from '@fluentui/react-icons'; | ||
import type { MenuProps } from '@fluentui/react-components'; | ||
|
||
const CutIcon = bundleIcon(CutFilled, CutRegular); | ||
const PasteIcon = bundleIcon(ClipboardPasteFilled, ClipboardPasteRegular); | ||
const EditIcon = bundleIcon(EditFilled, EditRegular); | ||
|
||
export const useMenuListContainerStyles = makeStyles({ | ||
container: { | ||
backgroundColor: tokens.colorNeutralBackground1, | ||
minWidth: '128px', | ||
minHeight: '48px', | ||
maxWidth: '300px', | ||
width: 'max-content', | ||
boxShadow: `${tokens.shadow16}`, | ||
paddingTop: '4px', | ||
paddingBottom: '4px', | ||
}, | ||
}); | ||
|
||
export const ControlledCheckboxItems = () => { | ||
const styles = useMenuListContainerStyles(); | ||
const [checkedValues, setCheckedValues] = React.useState<Record<string, string[]>>({ edit: ['cut', 'paste'] }); | ||
const onChange: MenuProps['onCheckedValueChange'] = (e, { name, checkedItems }) => { | ||
setCheckedValues(s => { | ||
return s ? { ...s, [name]: checkedItems } : { [name]: checkedItems }; | ||
}); | ||
}; | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<MenuList checkedValues={checkedValues} onCheckedValueChange={onChange}> | ||
<MenuItemCheckbox icon={<CutIcon />} name="edit" value="cut"> | ||
Cut | ||
</MenuItemCheckbox> | ||
<MenuItemCheckbox icon={<PasteIcon />} name="edit" value="paste"> | ||
Paste | ||
</MenuItemCheckbox> | ||
<MenuItemCheckbox icon={<EditIcon />} name="edit" value="edit"> | ||
Edit | ||
</MenuItemCheckbox> | ||
</MenuList> | ||
</div> | ||
); | ||
}; |
54 changes: 54 additions & 0 deletions
54
...ges/react-components/react-menu/stories/MenuList/MenuListControlledRadioItems.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as React from 'react'; | ||
|
||
import { MenuList, MenuItemRadio, makeStyles, tokens } from '@fluentui/react-components'; | ||
import { | ||
bundleIcon, | ||
CutRegular, | ||
CutFilled, | ||
ClipboardPasteRegular, | ||
ClipboardPasteFilled, | ||
EditRegular, | ||
EditFilled, | ||
} from '@fluentui/react-icons'; | ||
import type { MenuProps } from '@fluentui/react-components'; | ||
|
||
const CutIcon = bundleIcon(CutFilled, CutRegular); | ||
const PasteIcon = bundleIcon(ClipboardPasteFilled, ClipboardPasteRegular); | ||
const EditIcon = bundleIcon(EditFilled, EditRegular); | ||
|
||
export const useMenuListContainerStyles = makeStyles({ | ||
container: { | ||
backgroundColor: tokens.colorNeutralBackground1, | ||
minWidth: '128px', | ||
minHeight: '48px', | ||
maxWidth: '300px', | ||
width: 'max-content', | ||
boxShadow: `${tokens.shadow16}`, | ||
paddingTop: '4px', | ||
paddingBottom: '4px', | ||
}, | ||
}); | ||
|
||
export const ControlledRadioItems = () => { | ||
const styles = useMenuListContainerStyles(); | ||
const [checkedValues, setCheckedValues] = React.useState<Record<string, string[]>>({ font: ['calibri'] }); | ||
const onChange: MenuProps['onCheckedValueChange'] = (e, { name, checkedItems }) => { | ||
setCheckedValues(s => ({ ...s, [name]: checkedItems })); | ||
}; | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<MenuList checkedValues={checkedValues} onCheckedValueChange={onChange}> | ||
<MenuItemRadio icon={<CutIcon />} name="font" value="segoe"> | ||
Segoe | ||
</MenuItemRadio> | ||
<MenuItemRadio icon={<PasteIcon />} name="font" value="calibri"> | ||
Calibri | ||
</MenuItemRadio> | ||
<MenuItemRadio icon={<EditIcon />} name="font" value="arial"> | ||
Arial | ||
</MenuItemRadio> | ||
</MenuList> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.