Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFS (Responsive font size) implementation #23816

Merged
merged 1 commit into from
Feb 7, 2019

Conversation

MartijnCuppens
Copy link
Member

@MartijnCuppens MartijnCuppens commented Sep 3, 2017

Fixes #23053

  • RFS is disabled by default and can be switched on with $enable-responsive-font-sizes
  • font-size-properties are switched to the @include font-size()-mixin. Stylelint prevents the usage of font-size property.
  • Basic documentation added + link to github repo for further documentation.
  • RFS is enabled to rescale font-sizes of titles on the docs page.

Demo with RFS enabled available here (this is not the default behaviour, but would be the behaviour if $enable-responsive-font-sizes was true): https://project-rfs.github.io/

TODO:

  • Remove fusv false warning workaround
  • Decide whether or not we're going to keep $input-height-sm and $input-height-lg > no
  • Test if we should increase the minimum font size to 1.25rem > yes

@MartijnCuppens
Copy link
Member Author

MartijnCuppens commented Sep 3, 2017

@mdo: what do you think about this?

@mdo
Copy link
Member

mdo commented Dec 28, 2017

Thanks for keeping this up to date. I'm slating this for sure for 4.1, but I'll see if we should put it into 4.0 depending on a few other things.

@MartijnCuppens
Copy link
Member Author

MartijnCuppens commented Jan 6, 2018

Update:
It's now possible to disable responsive font-sizes for page by adding the .disable-responsive-font-size class to the body or html. This class can also be added to other elements.

Minimum font-size is also increased to 1rem, which prevents the default text from scaling down.

@wolfy1339
Copy link
Contributor

$enable-hover-media-query was not deprecated

@patrickhlauke
Copy link
Member

This is all voodoo to me, but one request: make sure that even if using vh/vw etc, that there's a component for font sizing tied to something else like px/rem/em. Otherwise (when a font size is purely related to viewport dimensions and nothing else) you kill the user's ability to (full page) zoom on desktop and change the size the text is rendered at (as yes, the viewport dimensions change, but the font size would then change proportionally in the opposite direction, meaning the apparent font size is never actually altered).

@MartijnCuppens
Copy link
Member Author

MartijnCuppens commented Jan 23, 2018

@patrickhlauke, It's possible to add the disable-responsive-font-size class to achieve this:
https://codepen.io/MartijnCuppens/pen/PEgNVM?editors=1100

Also, the font size is never purely related to viewport.

@MartijnCuppens MartijnCuppens changed the title RFS implementation RFS (Responsive font size) implementation Jun 3, 2018
@MartijnCuppens
Copy link
Member Author

There are several ways to implement this depending on what should be the default value for $rfs-class.

In the current implementation I've set $rfs-class: "disable";. This way, it's easy to disable responsive font sizes within the html by adding the .disable-responsive-font-size class. An example of this can be viewed here: https://codepen.io/MartijnCuppens/pen/PEgNVM?editors=1100 The class can also be added to the html or the body to disable responsive font sizes on the whole page. Downside of this implementation is that more css is generated (that's why I needed to increase the maxSize in package.json) and it increases specificity.

Another approach is to use $rfs-class: false;. This is the most performant solution but the .disable-responsive-font-size class cannot be added to elements. It can of course still be changed in scss, but I can imagine some people load the Bootstrap css via a CDN may prefer their font-size doesn't change. A possible solution for this is to generate 2 css versions: one with and one without responsive font-sizes.

@vladimirmartsul
Copy link

@MartijnCuppens, why not a $enable-rfs: false; (disabled by default) param like other in _variables.scss ?

@MartijnCuppens
Copy link
Member Author

@vladimirmartsul, that might be a good idea. This wouldn't cause a lot of changes by default while developers can still easily enable responsive font sizes if they want to.

@MartijnCuppens
Copy link
Member Author

I discovered changing the padding of buttons and inputs from em to rem can cause issues when upgrading Bootstrap, working on a solution for that.

I'll try to implement RFS in a way that it wouldn't have any influence on the current Bootstrap at all when it's disabled.

@MartijnCuppens
Copy link
Member Author

I've now disabled the responsive font sizing by default so that the css files are exactly the same (apart from property order).

Responsive font sizing can be enabled with $enable-responsive-font-sizes.

@andresgalante andresgalante requested a review from mdo September 7, 2018 14:43
@andresgalante
Copy link
Collaborator

Hi @MartijnCuppens, thanks for another great PR. I think that responsive font sizing is a killer feature to have.

My worried is that what this feature asks contributors might outweigh its value. Once we merge it we'll be asking contributors to include responsive-font-size every time they define a base font size. This adds a new level of complexity that makes Bootstrap harder to maintain and develop.

It'll be up to @mdo to decide if he wants this feature in Bootstrap or not. If we decide to add it I think we should either have a very strong linter or some kind of postCSS that automatically adds the artifact around the font size declarations.

@MartijnCuppens
Copy link
Member Author

@andresgalante, at this moment there's also a border-radius and a transition mixin for other properties.

I've also added the font-size property to the declaration-property-value-blacklist which will trigger an error if the font-size property is instead of the mixin.

site/index.html Outdated Show resolved Hide resolved
@MartijnCuppens MartijnCuppens force-pushed the rfs-rem-implementation branch from f7c0d38 to eadf3c2 Compare January 1, 2019 17:41
@planetoftheweb
Copy link
Contributor

This is really slick. One of my pet peeves is that I always want fonts on my phone to be bigger, not smaller. I like the limits placed here on the sample site, they seem reasonable and I like that there's a variable for setting the minimum. Well done.

@MartijnCuppens MartijnCuppens force-pushed the rfs-rem-implementation branch 3 times, most recently from a7250be to cc87c5e Compare January 17, 2019 17:43
@MartijnCuppens MartijnCuppens force-pushed the rfs-rem-implementation branch 3 times, most recently from 3981f4a to fa1e091 Compare January 29, 2019 18:09
@twbs twbs deleted a comment from gijsbotje Feb 7, 2019
@MartijnCuppens MartijnCuppens merged commit 51375ab into twbs:v4-dev Feb 7, 2019
@MartijnCuppens MartijnCuppens deleted the rfs-rem-implementation branch February 7, 2019 22:32
@MartijnCuppens
Copy link
Member Author

Never thought I would merge this myself, thanks a lot Bootstrap community ❤️

@mdo mdo mentioned this pull request Feb 8, 2019
@weilinzung
Copy link

weilinzung commented Feb 11, 2019

Just updated to 4.3.0. All of the font sizes are messed up.

I use this custom mixins with the Bootstrap 4: https://www.smashingmagazine.com/2015/06/responsive-typography-with-sass-maps/

I am confused because I add this mixins to as own which should not effect any updates from Bootstrap. All of updates below 4.3.0 are fine.

When I inspect it, it looks like outputting the SASS.
font-size: (null: 3rem, 1.2, lg: 2.6rem, md-max: 1.6rem, xs-md: 1.5rem);

@MartijnCuppens
Copy link
Member Author

Hi @weilinzung,

Bootstrap now uses the font-size mixin from RFS. It looks like you're passing a sass map to the mixin while you should just pass a font size to it. It doesn't work the same as the article you're referring to.

@LeaTark
Copy link

LeaTark commented Feb 12, 2019

Is there a compiled css on the cdn with rfs enabled?

@XhmikosR
Copy link
Member

No, because there's no official build with the option enabled.

@weilinzung
Copy link

@MartijnCuppens Maybe change the custom mixins to not using font-size?

@weilinzung
Copy link

@MartijnCuppens Also, what is the official way to do responsive fonts then? Any new Dos?

@MartijnCuppens
Copy link
Member Author

@weilinzung,
We're not going to change the name of the mixin since font-size is the most appropriate name.
You can find the documentation about the responsive font sizes in the Github repo: https://github.com/twbs/rfs

@weilinzung
Copy link

weilinzung commented Feb 12, 2019

@MartijnCuppens What if the sizes are not what I want that from the automatic rescaling on smaller devices? This is a really good feature, but also what about line-height?
In typographic design, line-height should alway works with font size.

@mdo
I think the option to disable this new feature should be not overwriting the font-size property.
Currently, $enable-responsive-font-sizes: false is still overwriting the font-size property.
Overwriting the entire font-size property is limiting custom mixins.

@MartijnCuppens
Copy link
Member Author

@weilinzung, we want to provide a solution that works out of the box without the need of further configuration. If you want you own implementation of the font sizes you can overwrite the mixin in your own custom configuration.

I'm going to lock the conversation on this PR because it we're deviating from the subject of it.

@twbs twbs locked as too heated and limited conversation to collaborators Feb 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.