<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Xu Cheng on Medium]]></title>
        <description><![CDATA[Stories by Xu Cheng on Medium]]></description>
        <link>https://medium.com/@drxcheng?source=rss-6e47a4e872d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*4wV9T01KSSDFf5wA35efzA.jpeg</url>
            <title>Stories by Xu Cheng on Medium</title>
            <link>https://medium.com/@drxcheng?source=rss-6e47a4e872d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 18:57:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@drxcheng/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[My takeaways from #a11yTO 2020 Conference]]></title>
            <link>https://drxcheng.medium.com/my-takeaways-from-a11yto-2020-conference-c0450e655eee?source=rss-6e47a4e872d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0450e655eee</guid>
            <category><![CDATA[accessibility]]></category>
            <category><![CDATA[a11y]]></category>
            <dc:creator><![CDATA[Xu Cheng]]></dc:creator>
            <pubDate>Sat, 31 Oct 2020 04:56:22 GMT</pubDate>
            <atom:updated>2020-10-31T04:56:22.460Z</atom:updated>
            <content:encoded><![CDATA[<p>A couple of years ago a potential customer demanded accessibility (a11y) in our software. We had little a11y consideration at that time, so started by adding tabIndex and aria-label. I heard the word “accessibility” before but had little knowledge about it. As I read more, I understood it is much more than that, and I became more and more fascinated with it.</p><p><a href="https://conf.a11yto.com/">#a11yTO 2020</a> is the first conference I’ve attended on this topic. It is virtual because of the year 2020 (I have to get up early since I’m on the west coast). Overall it was a well-organized conference (despite some tech issues). I learned a lot from it, and here are my takeaways from it (I will skip “accessibility is important” as a takeaway):</p><h4>A11y is a teamwork</h4><p>From top to bottom: the company/organization needs to commit to a11y compliance; the product team needs to prioritize work for a11y; the design team needs to produce accessible design; the development team needs to implement accessible products, the test team needs to test a11y. It is not a one-man-show.</p><h4>A11y can’t be done overnight</h4><p>Because of the above point, it’s not possible that a person being heroic and fixing the a11y problem overnight. Everyone should have a11y in mind and the team should have a plan. Also, from experience, there is less overhead when a11y is considered at the beginning than fixing issues afterwards.</p><h4>“Delight is the icing, usability is the cake”</h4><p>It was my favourite quote from one talk. I immediately started to question a feature I am developing (it’s a drag-and-drop feature, and it turned out the library I am using supports keyboard). When talking about a11y, the fundamental thing is about how to use the product. If the product is hard to use by different users, e.g., mouse users, keyboard users, screen reader users, how the product looks doesn’t matter then.</p><h4>Copy is important</h4><p>One talk from the conference was about copywriting. It is obvious but important to know that “no one complains that it’s too easy to read”. I resonate a lot: English is my second language and language art has been my nemesis since elementary school, so I appreciate simple language very much. There are tools to help you improve copywriting, such as <a href="https://datayze.com/readability-analyzer.php">Readability Analyzer</a>.</p><h4>A11y is not just for software, it is everywhere</h4><p>One talk is about emoji, which I never thought it has anything to do with a11y. For example, posting a tweet with emoji will cause unexpected behaviour from screen readers. To be honest, I think this is something emoji creator and screen reader should improve, but in the meantime, people should be aware of such issues and probably should avoid using emoji when posting important announcements on social media.</p><h4>There is a lot to learn</h4><p>In general, a11y can be very broad and touches lots of areas. From a programming point of view, there are many technologies and tools. One doesn’t have to know everything to begin. An a11y mind is foremost.</p><p>At last, be inclusive and bring people together.</p><p>(and stay safe!)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0450e655eee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My journey from CSS Modules to CSS-in-JS]]></title>
            <link>https://drxcheng.medium.com/my-journey-from-css-modules-to-css-in-js-b61ef397e87e?source=rss-6e47a4e872d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b61ef397e87e</guid>
            <category><![CDATA[js]]></category>
            <category><![CDATA[css-in-js]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[css-modules]]></category>
            <category><![CDATA[material-ui]]></category>
            <dc:creator><![CDATA[Xu Cheng]]></dc:creator>
            <pubDate>Fri, 29 Nov 2019 19:14:59 GMT</pubDate>
            <atom:updated>2020-11-03T20:13:16.022Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*D1dNLYu5tJ-nZf-M4qhPPA.png" /></figure><p>I recently started a <a href="https://reactjs.org/">React</a> + <a href="https://material-ui.com/">Material-UI</a> project. I naturally chose CSS modules (SASS modules to be exact) for styling over CSS-in-JS because I was more familiar with CSS/SASS. I also added <a href="https://github.com/Jimdo/typings-for-css-modules-loader">typings-for-css-modules-loader</a> in <a href="https://webpack.js.org/">Webpack</a> config for adding typing in <a href="https://www.typescriptlang.org/">TypeScript</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FRrVzUOXldFe8M%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FRrVzUOXldFe8M%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FRrVzUOXldFe8M%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5ee627c67ff4ec3e4e0d897500ee961/href">https://medium.com/media/c5ee627c67ff4ec3e4e0d897500ee961/href</a></iframe><p>Then I started to realize a few issues.</p><p>For example, Webpack will generate .d.ts file automatically, but not that reliable. Sometimes I need to go back and forth and save (which triggers compiling and hot reloading) the component file itself, the component file which imports this component, and the CSS file.</p><p>But one other issue raises the red flag for me: <strong>customizing/overriding MUI styling is painful using CSS Modules</strong>.</p><p>For example, I have a simple icon button, but I need it to be smaller than the MUI default. And this is the code:</p><pre>// MyIcon.tsx<br>import * as React from &#39;react&#39;;<br>import IconButton from &#39;@material-ui/core/IconButton&#39;;<br>import Close from &#39;@material-ui/icons/Close&#39;;<br>import * as styles from &#39;./MyIcon.module.scss&#39;;</pre><pre>const MyIcon: React.FunctionComponent = () =&gt; (<br>    &lt;IconButton className={styles.button}&gt;<br>        &lt;Close /&gt;<br>    &lt;/IconButton&gt;<br>);</pre><pre>export default MyIcon;</pre><pre>// MyIcon.module.scss<br>.button {<br>    padding: 0 0.5em !important;<br>    color: purple !important;<br>    min-width: 0;<br>}</pre><pre>// MyIcon.module.scss.d.ts<br>export const button: string;</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FglmRyiSI3v5E4%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FglmRyiSI3v5E4%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FglmRyiSI3v5E4%2Fgiphy-downsized-large.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="320" frameborder="0" scrolling="no"><a href="https://medium.com/media/3db53332078170a5a15f15bb2120c15d/href">https://medium.com/media/3db53332078170a5a15f15bb2120c15d/href</a></iframe><p>See those !important ? My styles won’t work without it. Why? Because MUI styling somehow has higher precedence. And sometimes it begins a guessing game, should I add or not?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/1*P5lTlQ0KBf0fVULNvt57pg.png" /><figcaption>padding and colour of `button` get overridden</figcaption></figure><p>I was told there might be a solution from Webpack config but I’m not comfortable messing with Webpack. So if anyone has any suggestions and example, I’m happy to listen.</p><p>So I go back to the beginning. I chose CSS because I’m more familiar with it. This is so NOT ME. I should not be afraid of trying new things.</p><p>I started some research on CSS-in-JS. Well, it didn’t take long, because Material-UI core styling is using <a href="https://cssinjs.org/">JSS</a>. The dependency is built-in so there is no additional bundle size overhead. Furthermore, I have already used some JSS for overriding the MUI theme globally in the code. Although there might be more popular or powerful CSS-in-JS libraries, using JSS here should be the first choice.</p><p>Then I re-wrote the component:</p><pre>// MyIcon.tsx<br>import * as React from &#39;react&#39;;<br>import IconButton from &#39;@material-ui/core/IconButton&#39;;<br>import Close from &#39;@material-ui/icons/Close&#39;;<br>import { makeStyles } from &#39;@material-ui/core/styles&#39;;</pre><pre>const useStyles = makeStyles({<br>    root: {<br>        padding: &#39;0 0.5em&#39;,<br>        color: &#39;purple&#39;,<br>        minWidth: 0,<br>    },<br>});</pre><pre>const MyIcon: React.FunctionComponent = () =&gt; {<br>    const classes = useStyles();</pre><pre>    return (<br>        &lt;IconButton className={classes.root}&gt;<br>            &lt;Close /&gt;<br>        &lt;/IconButton&gt;<br>    );<br>};</pre><pre>export default MyIcon;</pre><p>That’s it. All in one file. And it works without !important.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*MaZPG_PbYP1gQGGq-bHvdg.png" /></figure><p>So let’s compare. I basically copy the stylesheet to .tsxfile. There is a bit of work (and a bit learning curve) but the idea is simple: 1) convert the CSS keywords from <strong>kebab-case</strong> to <strong>camelCase</strong>, 2) add a quote to CSS values, or make pixel value a number without “px”.</p><p>There are different ways to utilize JSS in the component but since I’m using Material-UI, I use makeStylesto get a <a href="https://reactjs.org/docs/hooks-intro.html"><strong><em>hook</em></strong></a> and then get the classes inside the functional component.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fm4g1vtdI6EXrG%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fm4g1vtdI6EXrG%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fm4g1vtdI6EXrG%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="253" frameborder="0" scrolling="no"><a href="https://medium.com/media/f17d78a3e6b8ab52577b2cdebeecf7ef/href">https://medium.com/media/f17d78a3e6b8ab52577b2cdebeecf7ef/href</a></iframe><p>In short, I like my new choice: everything is JavaScript and is in one file (if you say the file will get too big, then I’ll argue you should break your component into smaller pieces); no more guessing game with !important; no need to deal with CSS typing.</p><h3>And more studies came</h3><p>The above example code shows how to use JSS in React functional component, but it won’t work with the React class component, because makeStyles generates a hook, which can only be called inside a functional component. So how to use JSS for the <strong>class component</strong>?</p><p>The code can be rewritten into this:</p><pre>import * as React from &#39;react&#39;;<br>import IconButton from &#39;@material-ui/core/IconButton&#39;;<br>import Close from &#39;@material-ui/icons/Close&#39;;<br>import { withStyles, WithStyles } from &#39;@material-ui/core/styles&#39;;</pre><pre>const myStyles = () =&gt; {<br>    return {<br>        root: {<br>            padding: &#39;0 0.5em&#39;,<br>            color: &#39;purple&#39;,<br>            minWidth: 0,<br>        },<br>    };<br>};</pre><pre>class MyIcon extends React.Component&lt;WithStyles&gt; {<br>    constructor(props: WithStyles) {<br>        super(props);<br>    }</pre><pre>    public render() {<br>        const { classes } = this.props;</pre><pre>        return (<br>           &lt;IconButton className={classes.root}&gt;<br>               &lt;Close /&gt;<br>           &lt;/IconButton&gt;<br>        );<br>    }<br>}</pre><pre>export default withStyles(myStyles)(MyIcon);</pre><p>It is using MUI’s withStyles instead. It is a HOC (Higher-Order Components) rendering custom component with custom styles. It’s not bad either!</p><p>So what else can I use in JSS? First I tried the <strong>pseudo-class</strong>. Instead of using MUI IconButton , I just simply tried a div :</p><pre>import * as React from &#39;react&#39;;<br>import IconButton from &#39;@material-ui/core/IconButton&#39;;<br>import Close from &#39;@material-ui/icons/Close&#39;;<br>import { makeStyles } from &#39;@material-ui/core/styles&#39;;</pre><pre>const useStyles = makeStyles({<br>    root: {<br>        padding: &#39;0 0.5em&#39;,<br>        color: &#39;purple&#39;,<br>        minWidth: 0,<br>        &#39;&amp;:hover&#39;: {<br>            cursor: &#39;pointer&#39;,<br>            backgroundColor: &#39;orange&#39;,<br>        },<br>   },<br>});</pre><pre>const MyIcon: React.FunctionComponent = () =&gt; {<br>    const classes = useStyles();</pre><pre>    return (<br>        &lt;div className={classes.root}&gt;<br>            &lt;Close /&gt;<br>        &lt;/div&gt;<br>    );<br>};</pre><pre>export default MyIcon;</pre><p>Voila! Next, <strong>nested class</strong>:</p><pre>import * as React from &#39;react&#39;;<br>import IconButton from &#39;@material-ui/core/IconButton&#39;;<br>import Close from &#39;@material-ui/icons/Close&#39;;<br>import { makeStyles } from &#39;@material-ui/core/styles&#39;;</pre><pre>const useStyles = makeStyles({<br>    root: {<br>        padding: &#39;0 0.5em&#39;,<br>        color: &#39;purple&#39;,<br>        minWidth: 0,<br>        &#39;&amp; label&#39;: {<br>            textTransform: &#39;uppercase&#39;,<br>        },<br>   },<br>});</pre><pre>const MyIcon: React.FunctionComponent = () =&gt; {<br>    const classes = useStyles();</pre><pre>return (<br>        &lt;IconButton className={classes.root}&gt;<br>            &lt;label&gt;close&lt;/label&gt;<br>            &lt;Close /&gt;<br>        &lt;/IconButton&gt;<br>    );<br>};</pre><pre>export default MyIcon;</pre><p>Yep, also straightforward.</p><p>Any comments or suggestions are welcome! Peace out!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3o7qDEq2bMbcbPRQ2c%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3o7qDEq2bMbcbPRQ2c%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNWI0cHFrb3pqMmN0ZmZmcjZzcDhkZ2VraHBvaWRrNGJwc3I3dzg1OCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F3o7qDEq2bMbcbPRQ2c%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="300" frameborder="0" scrolling="no"><a href="https://medium.com/media/b50e0856a1d58349044443db720eb5cf/href">https://medium.com/media/b50e0856a1d58349044443db720eb5cf/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b61ef397e87e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>