apps/mantine.dev/src/pages/changelog/7-8-0.mdx
import { FormDemos, UseDebouncedCallbackDemos, UseFetchDemos, UseIsFirstRenderDemos, UseMapDemos, UseOrientationDemos, UseSetDemos, UseThrottledCallbackDemos, UseThrottledStateDemos, UseThrottledValueDemos } from '@docs/demos'; import { Layout } from '@/layout'; import { MDX_DATA } from '@/mdx';
export default Layout(MDX_DATA.Changelog780);
Start from version 1.14.4 postcss-preset-mantine
supports autoRem option that can be used to automatically convert all px values
to rem units in .css files.
module.exports = {
plugins: {
'postcss-preset-mantine': {
autoRem: true,
},
},
};
This option works similar to rem function. The following code:
.demo {
font-size: 16px;
@media (min-width: 320px) {
font-size: 32px;
}
}
Will be transformed to:
.demo {
font-size: calc(1rem * var(--mantine-scale));
@media (min-width: 320px) {
font-size: calc(2rem * var(--mantine-scale));
}
}
Note that autoRem converts only CSS properties, values in @media queries are
not converted automatically – you still need to use em function to convert them.
autoRem option does not convert values in the following cases:
calc(), var(), clamp() and url() functionscontent propertyrgb(), rgba(), hsl(), hsla() colorsIf you want to convert above values to rem units, use rem function manually.
useForm hook now supports uncontrolled mode.
Uncontrolled mode provides a significant performance improvement by reducing
the number of re-renders and the amount of state updates almost to 0. Uncontrolled
mode is now the recommended way to use the useForm hook for almost all use cases.
Example of uncontrolled form (form.values are not updated):
With uncontrolled mode, you can not access form.values as a state variable,
instead, you can use form.getValues() method to get current form values at any time:
import { useForm } from '@mantine/form';
const form = useForm({
mode: 'uncontrolled',
initialValues: { name: 'John Doe' },
});
form.getValues(); // { name: 'John Doe' }
form.setValues({ name: 'John Smith' });
form.getValues(); // { name: 'John Smith' }
form.getValues() always returns the latest form values, it is safe to use it
after state updates:
import { useForm } from '@mantine/form';
const form = useForm({
mode: 'uncontrolled',
initialValues: { name: 'John Doe' },
});
const handleNameChange = () => {
form.setFieldValue('name', 'Test Name');
// ❌ Do not use form.values to get the current form values
// form.values has stale name value until next rerender in controlled mode
// and is always outdated in uncontrolled mode
console.log(form.values); // { name: 'John Doe' }
// ✅ Use form.getValues to get the current form values
// form.getValues always returns the latest form values
console.log(form.getValues()); // { name: 'Test Name' }
};
form.watch is an effect function that allows subscribing to changes of a
specific form field. It accepts field path and a callback function that is
called with new value, previous value, touched and dirty field states:
You can now customize middlewares options in Popover component and
in other components (Menu, Select, Combobox, etc.)
based on Popover.
To customize Floating UI middlewares options, pass them as
an object to the middlewares prop. For example, to change shift
middleware padding to 20px use the following configuration:
import { Popover } from '@mantine/core';
function Demo() {
return (
<Popover
middlewares={{ shift: { padding: 20 } }}
position="bottom"
>
</Popover>
);
}
New use-fetch hook:
<Demo data={UseFetchDemos.usage} />New use-map hook:
<Demo data={UseMapDemos.usage} />New use-set hook:
<Demo data={UseSetDemos.usage} />New use-debounced-callback hook:
<Demo data={UseDebouncedCallbackDemos.usage} />New use-throttled-state hook:
<Demo data={UseThrottledStateDemos.usage} />New use-throttled-value hook:
<Demo data={UseThrottledValueDemos.usage} />New use-throttled-callback hook:
<Demo data={UseThrottledCallbackDemos.usage} />New use-orientation hook:
<Demo data={UseOrientationDemos.usage} />New use-is-first-render hook:
<Demo data={UseIsFirstRenderDemos.usage} />withKeyboardEvents={false} to disable up/down arrow keys handling