8

I am using Angular 15 with Angular material 15, then I have added Tailwind CSS as per the instruction https://tailwindcss.com/docs/guides/angular

The material component design got mismatched as shown below

enter image description here

The placeholder name is truncated as it should be

enter image description here

The line appears in the text box.

In the style.scss

@tailwind base;
@tailwind components;
@tailwind utilities;

Tailwind config

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./src/**/*.{html,ts}",
    ],
  theme: {
    extend: {},
  },
  plugins: [],
}
San Jaisy
  • 15,327
  • 34
  • 171
  • 290

4 Answers4

4

You must add into your tailwind.config.js in module.exports the next config:

corePlugins: { preflight: false },

Using the above solution can cause some problems with tailwindcss classes. For this reason it is better to add the following lines in style.scss:

.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field .mdc-notched-outline__notch { border-right-style: hidden; }

1

Tailwind by default adds a border on the right side of the items (something like that). Adding a border-style: none does solve this problem. You add the following code to your global styles file and it should work (at least it worked for me)

*, ::before, ::after {
  border-style: none;
}
  • UPDATE

Following the above method would also remove all the border styles from your app. Found the following solution which only effects the classes in mat-forms-field > mat-label

.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field
  .mdc-notched-outline__notch {
  border-right-style: hidden;
}
0

It has something to do with tailwind applying border-style: 'solid' to everything.

*, ::before, ::after {
  border-style: none;
}
Kyoss
  • 172
  • 1
  • 11
0

these all the styles I use to fix the material / tailwind combo:

//*******************************
//** Material / tailwind fixes **
//*******************************
.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field
  .mdc-notched-outline__notch {
  border-right-style: hidden;
}

.mat-mdc-input-element {
  box-shadow: none !important;
}

.sticky {
  position: sticky !important;
}

[type='text'],
[type='email'],
[type='url'],
[type='password'],
[type='number'],
[type='date'],
[type='datetime-local'],
[type='month'],
[type='search'],
[type='tel'],
[type='time'],
[type='week'],
[multiple],
textarea,
select {
  padding: 0;
  border: none;
}
Ruben
  • 8,956
  • 14
  • 63
  • 102