MUI Note
Congrats on MUI new version#
- @2021-09-17
- Renaming from Material-UI to MUI
- I was navigating to
mui icon
page with my Chrome Terminal command and I see a new UI and a new URL. For one second I thought my Chrome Terminal was down. But actually it is redirected from thematerial-ui
. Will keep reporting bugs. Congrats to the team. I prefer the new website UI to the one before. - Just see that they changed to
@mui
. . . I'm staying with v4 and do the migration later (procrastinate) - Usually I don't move to the new version but this time MUI X and new
styled
, newsx
props are giving me so many "illusions" of using it. I am actually considering migrating to v5. - Last straw: Strict Mode support
- To use the drop down menu correctly with strict mode, I think I should move. Problem was on findDOMNode
- At creating User Pool: if "email" is required, "unconfirmed" user cannot log in(sign in).
Migration from v4 to v5#
- @2021-09-19
v4
(only this line) :get Checkbox value from useRef:<REF>.current?.checked
- Migrating(v4->v5): In v4 migration, VIDEO: Effective Refactoring with Codemods by Edd Yerburgh: First expose to
codemod
,JSCodeshift
,AST
, (playground). I liked the video a lot, please do check it. - Anecdote
Fix Clicking Ripple Effect only half width#
- @2021-09-20
- Problem: Clicking Ripple only starts on the left half, not circle shape (ellipse).
- Solotion: In my
index.css
file, it was set* {max-width:100%}
. Changed it to100vw
(if no wide button) or remove this rule.
Trying to add animation/transition on dark mode toggle#
- @2021-09-22
-
Overriding with
index.css
doesn't work: My components hasComputed
Attr. like below, yet there's no transition.transition-delay 0s, 0s transition-duration 5s, 5s transition-property background-color, color transition-timing-function ease-in, ease-in
- Changing
.css
withyarn start
re-render will not "recreate the entire component tree"(quote origin=MUI#6685) while changing theme will, also input-boxes will be cleared.
-
Current best work-around:
- In short: Don't use MUI theme.
- joshwcomeau
- MUI#12827
- My solution: wait for MUI upgrade, having a lot faith in the team.
Change input box autofill style (:-webkit-autofill
)#
- @2021-09-23
- override
MuiOutlinedInput
style, in MUIv5 it is like this answer from me
How does ButtonGroup
works, with IconButton
and Button
?#
- @2021-10-06
-
The
React.cloneElement()
function will passprops
to children. The modularizedIconButton
needs to receive it properly. Three effects of this:- Modularizing
IconButton
changes color and hover background shape of element. - Passing empty props changes the
Button
color and border shape inButtonGroup
. IconButton
(both MUI original and customized) inButtonGroup
will cause two
Error/Warning
Warning: React does not recognize the `disableElevation` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `fullwidth` instead. If you accidentally passed it from a parent component, remove it from the DOM element. Warning: React does not recognize the `disableElevation` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `disableelevation` instead. If you accidentally passed it from a parent component, remove it from the DOM element. - Modularizing
-
The styling for the border is using
:not(:last-of-type)
(guess: on<button>
).IconButton
have root node of<button>
.
- In
Button
, ifhref
is defined, an<a>
element will be used as the root node (otherwise a<button>
), said in official doc.
-
This explains these two questions:
- Property
href
changes the right border of element, because it changes the<button>
to a<a>
Asked and answered onSO
- When all
IconButton
-s are on one side, other<Button>
-s havehref
property, the hover background shape of lastIconButton
will change, because this would change the result of:not(:last-of-type)
CSS query on<button>
-s. * [Deprecated]mwe page hosted withGH
Pages.
- Property
- [Deprecated] Created an issue on MUI official repo.
- This is fixed by the PR MUI#28645
Import svg from DiceBear Jdenticon API#
- @2021-10-11
- Selected style
jdenticon
fromDiceBear
- Correct way of implementing it: use
<img>
withbase64
full answer onSO
: (the answer that I finally used) <SvgIcon>
is not the way of using an svg with multiple<path>
, not with children nor with component<SvgIcon children={jdenticon} />
. It seems to be used for importedsvg
or with<path>
info, explained here and official document.<Icon>
like in this answer is not very useful, adding only 2 propscolor
andfontSize
(see API).- The
<svg>
tag can be rendered whilenew DOMParser().parseFromString(UTF8SvgTagString, "image/svg+xml")
can't, at least not for<svg>
like this one with multi-path. Method fromSO
fetch()
will return a response with typeReadableStream
. To get the data inside, use.then(res=>res.text())
or other methods (like.body()
)- Try with
DiceBear
NPM Buffer
andbase64
src:- Buffer can be created from both
latin1
andutf8
. (tested myself) btoa()
andnew Buffer()
are deprecated. Now useBuffer.from().toString('base64')
(partially credit). Just see that it is written in the answer that I finally used.escape()
andunescape()
are not necessary, just less length.
- Buffer can be created from both
- Didn't try
dangerouslySetInnerHTML
for the danger.
<IconButton>
does not extend <Button>
#
- @2021-10-12
- Easy to check on
<IconButton >
API, that it inherits<ButtonBase>
. - Thought it wrong all the time including in comments of MUI-PR#28645
Custom attributes with Typescript#
- @2021-10-21
- Use a
-
(dash) in the component, fromSO
- The prefix doesn't have to be
data-
(fordiv
it works)
Custom hook with class component#
- @2021-10-21
- It is easy to apply but seems not in official doc, from
SO
- This page for typescript shows how to do the enhancers HOC clearly.
- [ ] Tried to extend a class with the HOC and I don't know how to do it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Set attribute of a MUI component#
- @2021-10-21
- Wrap it as a new component, like this (props goes last to overwrite, sx needs merge.)
1 2 3 |
|