DEV Community

Cover image for How to style a PCF like a standard Model Driven App control
Riccardo Gregori
Riccardo Gregori

Posted on

4

How to style a PCF like a standard Model Driven App control

After this article I had an interesting exchange with David Rivard on how to manually tweak the style of Fluent UI 9 controls to make it look like the standard, model-driven, ones.

In this post I will show the results of our try-and-errors, for future reference.

πŸ’₯ The problem

By default, even if you implement a new Virtual PCF Control, the theme used by standard Model-Driven App controls differs from the one employed in Canvas Apps, and both, in turn, differ from the default theme of Fluent UI, used out of the box by the PCF controls.

Differences between standard theme and Canvas/Model Driven One

In the thread David suggested to apply the following attribute to my control:

  • appearance="filled-darker"

Effectively, that did the trick when the form is active, but not when the form/control is disabled 😠.

Active vs Inactive

πŸ’‘ The solution

Stating from David suggestion, and after a lot of try-and-errors, I found the following workaround. I tested it with Input and Select controls, and it quite works.

🎨 Step 1 - Create a custom style

Using Fluent UI makeStyles function, create a custom style with the following content:

import { makeStyles } from '@fluentui/react-components';

const useStyles = makeStyles({
  filledDarker: {
    ...shorthands.borderStyle('solid'),
    ...shorthands.borderWidth('1px'),
    ...shorthands.borderColor(tokens.colorNeutralBackground1Hover),
    'border-radius': "4px !important",
    backgroundColor: tokens.colorNeutralBackground1Hover,
    color: tokens.colorNeutralForeground1 + " !important",
    cursor: 'default',
    minWidth: "50px",
    '> input': {
      ...shorthands.borderStyle('none'),
      color: tokens.colorNeutralForeground1 + " !important",
      cornerRadius: tokens.borderRadiusMedium,
      cursor: 'text',
    },
    '> select': {
      ...shorthands.borderStyle('none'),
      color: tokens.colorNeutralForeground1 + " !important",
      cursor: 'default',
    },
    '> span': {
      ...shorthands.borderStyle('none'),
      color: tokens.colorNeutralForeground1 + " !important",
      cornerRadius: tokens.borderRadiusMedium,
      cursor: 'default',
    }
  },
});
Enter fullscreen mode Exit fullscreen mode

πŸ“ Step 2 - Apply the custom style to your control

Remember to apply both attributes:

  • className= to the style created above
  • appearance="filled-darker"
import * as React from 'react';
import { Input } from '@fluentui/react-components';

const MyComponent: React.FC = () => {

...

return (
    <Input 
      className={styles.filledDarker}
      appearance="filled-darker"
      ...
      />
  );
};
Enter fullscreen mode Exit fullscreen mode

πŸ€” Why does it "quite" works?

Standard controls, when disabled, have a nice dark-gray underline effect on focus:

Underline effect on disabled controls

I wasn't able to reproduce the same effect with my CSS.

πŸ—¨οΈ If you have any suggestion on how to make it work, drop a comment here! πŸ’¬

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

πŸ‘‹ Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay