Skip to content

[BREAKING] fix(react-text): remove default text styles#23254

Closed
theerebuss wants to merge 6 commits into
microsoft:masterfrom
theerebuss:remove-default-text-styles
Closed

[BREAKING] fix(react-text): remove default text styles#23254
theerebuss wants to merge 6 commits into
microsoft:masterfrom
theerebuss:remove-default-text-styles

Conversation

@theerebuss

@theerebuss theerebuss commented May 25, 2022

Copy link
Copy Markdown
Contributor

Current Behavior

Text re-applies by default what's already enforced by FluentProvider

New Behavior

Text will no longer apply these styles by default with the introduction of a new default for the props - none.
Documentation was also updated and cleaned up to match the rest of the components.

FluentProvider now also applies line-height by default.

Related Issue(s)

Fixes #22855

@codesandbox-ci

codesandbox-ci Bot commented May 25, 2022

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit d79f38b:

Sandbox Source
@fluentui/react 8 starter Configuration
@fluentui/react-components 9 starter Configuration

Comment on lines -30 to -47
Or by installing only the `@fluentui/react-text` package. Keep in mind you'll need to install the FluentProvider package as well:

```sh
npm install @fluentui/react-text
npm install @fluentui/react-provider
```

```jsx
import { FluentProvider } from '@fluentui/react-provider';
import { Text } from '@fluentui/react-text';

const App = () => (
<FluentProvider>
<Text>Fluent UI Text!</Text>
</FluentProvider>
);
```

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer recommended due to possible dependency clashing.

## Typography wrappers

![List of typography variants by sorted descending by size](./assets/typography-examples.gif 'Typography wrapper list')
![List of typography variants by sorted descending by size](./assets/typography-examples.png 'Typography wrapper list')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated image to contain the new typography wrapper Caption2 introduced in #22934

## API

For more information about the components, please refer to the [API documentation](https://aka.ms/fluentui-storybook).
For more information about the components, please refer to the [API documentation](https://react.fluentui.dev/?path=/docs/components-text--default).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Points to the new website, given that the URL should be final.

@fabricteam

fabricteam commented May 25, 2022

Copy link
Copy Markdown
Collaborator

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
181.169 kB
50.611 kB
181.239 kB
50.621 kB
70 B
10 B
react-components
react-components: FluentProvider & webLightTheme
34.078 kB
11.098 kB
34.148 kB
11.124 kB
70 B
26 B
react-provider
FluentProvider
14.127 kB
5.299 kB
14.197 kB
5.33 kB
70 B
31 B
react-text
Text - Default
10.904 kB
4.298 kB
10.968 kB
4.337 kB
64 B
39 B
react-text
Text - Wrappers
14.226 kB
4.714 kB
14.29 kB
4.766 kB
64 B
52 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-card
Card - All
60.746 kB
17.41 kB
react-card
Card
56.031 kB
16.147 kB
react-card
CardFooter
7.793 kB
3.327 kB
react-card
CardHeader
9.363 kB
3.841 kB
react-card
CardPreview
7.765 kB
3.35 kB
react-input
Input
22.163 kB
7.295 kB
react-spinbutton
SpinButton
42.132 kB
11.895 kB
🤖 This report was generated against 7bd33dbd7ddfc579e288c8081b8921be8cf421c5

@size-auditor

size-auditor Bot commented May 25, 2022

Copy link
Copy Markdown

Asset size changes

Size Auditor did not detect a change in bundle size for any component!

Baseline commit: 7bd33dbd7ddfc579e288c8081b8921be8cf421c5 (build)

@fabricteam

fabricteam commented May 25, 2022

Copy link
Copy Markdown
Collaborator

Perf Analysis (@fluentui/react-components)

Scenario Render type Master Ticks PR Ticks Iterations Status
FluentProviderWithTheme mount 262 247 10 Possible regression
All results

Scenario Render type Master Ticks PR Ticks Iterations Status
Avatar mount 942 907 5000
Button mount 572 565 5000
FluentProvider mount 1925 1864 5000
FluentProviderWithTheme mount 262 247 10 Possible regression
FluentProviderWithTheme virtual-rerender 224 215 10
FluentProviderWithTheme virtual-rerender-with-unmount 306 283 10
MakeStyles mount 1711 1699 50000

@spmonahan spmonahan added the Needs: API Breaking Change Tracking breaking changes for API surface area label May 25, 2022
@spmonahan spmonahan changed the title Remove default text styles [BREAKING] Remove default text styles May 25, 2022
@NotWoods

NotWoods commented May 25, 2022

Copy link
Copy Markdown
Contributor

none makes me think the font properties are going to get cleared out, and if I don't set a property then it will use defaults like "Times New Roman"/serif for font-family.

If that's not the case, 'initial' or 'inherit' would be more clear than 'none' and match CSS's keyword.

EDIT: unset is the best CSS keyword here because it maps to "not set". "none" still makes me think it maps to "initial" even with the JSDoc comment.

* Aligns text based on the parent container.
*
* @default start
* @default 'none'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about using inherit for the default value to better align with CSS keywords?

https://developer.mozilla.org/en-US/docs/Web/CSS/inherit

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a prop is nullable, the default can be for us to not set any style and leave them undefined. This can avoid creating another value in the union.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of having the prop be undefined by default. inherit doesn't feel like quite the right name and the prop is already optional.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think inherit would create more confusion as we wouldn't actually apply that. I went with none to keep it consistent with our lib as I'm not aware of any component working in undefined values, as we're forcing Required on component state.
I'm pro using undefined but it needs to be coherent and standardized.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO folks meant following:

-align?: 'none' | 'start' | 'center' | 'end' | 'justify';
+align?: 'start' | 'center' | 'end' | 'justify';

optional operator ads undefined type already

@NotWoods NotWoods May 26, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unset is another good option that matches CSS. The CSS keyword unset represents the default value and is equivalent to not setting the property at all.

All these properties default to inherit since they're inherited properties, so inherit is also a reasonable string even though its not explicitly applied. However, if you ever introduced a non-inherited property, you'd need a different string.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think unset could be used as that would go against implementation intent. we dont wanna do actual "reset" of css style definition.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we had additional offline sync with @andrefcdias on this - we will create a draft RFC for alignment across all component APIs on how to approach "default" values. once that will be resolved we can go back and re-solve this convo accordingly. ty!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RFC: #23304

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined is fine with me!

To clarify, unset means "not set by the component" rather than "reset" (aka initial). I felt that none implies actual "reset" which is why I've been asking for a name change :)

@spmonahan spmonahan self-assigned this May 25, 2022
@theerebuss theerebuss changed the title [BREAKING] Remove default text styles [BREAKING] fix(react-text): remove default text styles May 26, 2022
fontFamily: tokens.fontFamilyBase,
fontSize: tokens.fontSizeBase300,
fontWeight: tokens.fontWeightRegular,
...typographyStyles.body1,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leveraging typographyStyles to improve clarity on why we use said values and to avoid duplication.

@theerebuss
theerebuss marked this pull request as ready for review May 26, 2022 13:41
@theerebuss
theerebuss requested review from a team as code owners May 26, 2022 13:41
state.align === 'center' && styles.alignCenter,
state.align === 'end' && styles.alignEnd,
state.align === 'justify' && styles.alignJustify,
sizeMap[state.size],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌😍

@behowell

Copy link
Copy Markdown
Contributor

@andrefcdias we discussed this change in the ship meeting, and there was some concern about the changes to the Text component, and we didn't want to rush it in as a breaking change until we've had a chance to discuss more with the team.

But we wanted to get the FluentProvider lineHeight change in as soon as possible, so I split that change into a separate PR: #23279

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Text Needs: API Breaking Change Tracking breaking changes for API surface area

Projects

Development

Successfully merging this pull request may close these issues.

[Bug]: Should V9 Text add styles to root by default (without any props)?

8 participants