Conditionally override AntD Select styling in CSS - css

I have a form that contains an antD Select component.
<Select
name="SeasonId"
onChange={onSeasonChange}
placeholder="Choose Season"
>
// Select Options
</Select>
I want to be able to change the colour of the border (and box shadow) depending on a condition. I am able to change/override the css I need by adding the following into a separate CSS file:
.ant-select-selector:hover {
border-color: #1f9643e5 !important;
}
.ant-select-focused .ant-select-selector,
.ant-select-selector:focus,
.ant-select-selector:active,
.ant-select-open .ant-select-selector {
border-color: #1f9643e5 !important;
outline: 0 !important;
-webkit-box-shadow: 0 0 0 2px rgba(49, 139, 54, 0.342) !important;
box-shadow: 0 0 0 2px rgba(49, 139, 54, 0.342) !important;
}
This changes the styling to what I am after:#
However, I only want to apply this style-override to the Select if a certain condition is met in code (i.e. I have an isEditMode state bool). I may be missing something obvious but interested on hearing any suggestions.

Use a parent class name for your custom CSS code, and apply the class name to a parent element when the condition is true.
Example,
in your CSS file
.example.ant-select-selector:hover {
border-color: #1f9643e5 !important;
}
and in your JSX file,
<div className = {`${conditon ? 'example' :''}`} >
<Select />
</div>

Related

Vuetify remove dialog's box shadow

I want to remove the box-shadow from the dialog box of vuetify. Image of that -->
In chrome devTools if I set box-shadow to none it works. Like the image below.
But when I am adding a class with box-shadow none, it ain't working. Code for that-->
<v-dialog
v-model="assignedPRPaneldialog"
width="700"
content-class="vDialog"
>
<v-card v-if="GET_PRESS_RELEASE_ASSIGNED_DATA.length > 0">
<!-- {{ GET_PRESS_RELEASE_ASSIGNED_DATA }} -->
<v-card
v-for="(item, i) in GET_PRESS_RELEASE_ASSIGNED_DATA"
:key="i"
class="pa-2"
outlined
>
<CardPr :simple="true" :item="item" />
</v-card>
</v-card>
<v-card v-else>
<v-alert border="bottom" colored-border type="warning" elevation="0">
No Press Release yet.
</v-alert>
</v-card>
</v-dialog>
<style lang="scss" scoped>
div.vDialog {
box-shadow: none;
}
</style>
What should I do here? Thanks in advance.
There are two easy ways I know of to remove box-shadow from v-dialog (and v-menu).
1. Globally:
<style>
.v-dialog {
box-shadow: none;
}
</style>
2. Specific v-dialog (better way):
<v-dialog content-class="elevation-0">
...
</v-dialog>
Notice that it has to be content-class instead of just class.
And if you want to hide the overlay, too:
<v-dialog content-class="elevation-0" hide-overlay>
...
</v-dialog>
References:
v-dialog API, Vuetify Elevation helpers
From this code it's visible that shadow is added on element with .v-dialog class, so you're adding "no-shadow" style to the wrong element.
.v-dialog {
border-radius: 6px;
margin: 24px;
overflow-y: auto;
pointer-events: auto;
transition: 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
width: 100%;
z-index: inherit;
box-shadow: 0px 11px 15px -7px rgb(0 0 0 / 9%), 0px 24px 38px 3px rgb(0 0 0 / 5%), 0px 9px 46px 8px rgb(0 0 0 / 3%);
You can add your class directly to <v-dialog> component, or use elevation-0 class.
EDIT:
If you want to remove dialog's overlay, use hide-overlay prop
Following m4n0's suggestion, found out any class that I use on v-dialog component was applying in the dialog inside v-application--wrap. But as you can see outside application--wrap, there is another v-dialog class is appearing. So currently I removed the scoped property from style, which is now giving me my desired output. Probably targeting the class should be a better option. I will try that out later.
I am not sure though if it is an intended behavior or I made a mistake somewhere.

Angular mat-button-toggle focus overlay color

I have a mat-toggle-button-group in a form:
<form [formGroup]="form" class="mb-4">
<mat-button-toggle-group
name="carrier"
aria-label="Choose Carrier"
#carrierSelection="matButtonToggleGroup"
formControlName="carrierChoice"
[value]="carrierChosen"
>
<mat-button-toggle [value]="carrier" *ngFor="let carrier of carriers">
<img alt="Carrier: {{ carrier | uppercase }}" src="/assets/sending/images/carriers/{{ carrier }}/tab-logo.svg" />
</mat-button-toggle>
</mat-button-toggle-group>
</form>
It insists on showing a heavy black border around the button when it is focused, via tab key or clicked.
I inspect the div <div class="mat-button-toggle-focus-overlay"></div> and find this:
So, first I tried this:
.mat-button-toggle-checked .mat-button-toggle-focus-overlay {
border-bottom: 0 !important;
background-color: transparent !important;
}
No luck still a heavy black line, although inspecting it now shows my overrides:
Which I do not understand.
Next, I try this:
.mat-button-toggle-focus-overlay,
.mat-button-focus-overlay {
box-shadow: var(--focus_shadow) var(--focus);
background-color: transparent !important;
border: 0 !important;
}
When I inspect the <div class="mat-button-toggle-focus-overlay"></div> in the app, it actually shows it has my styles:
But the black line persists.
Apparently, Chrome changed the focus treatment recently and Edge Chromium decided to use a heavy black line for focus.
so I wrapped the toggle group in a DIV and set this:
.carrier-toggle {
.mat-button-toggle-label-content,
.mat-button-toggle-button,
.mat-button-toggle {
outline: none !important;
}
}
and then I set my own focus style, with a background color.
.mat-button-toggle,
.mat-button-toggle-group-appearance-standard .mat-button-toggle + .mat-button-toggle {
&:focus {
background-color: var(--rich200);
border: 0;
}
}

Change bootstrap file input focus glow color in reactjs

I have this file input that I would like to change the color of the blue glow when I select it.
<Form className='col-12'>
<input type='file' className='custom-file-input' id='batch-file'
onChange={e => this.setState({file: e.target.files[0], fileName: e.target.files[0].name})}/>
<label className='custom-file-label' htmlFor='customFile'>{this.state.fileName}</label>
</Form>
Ive tried changing CSS to this:
input:focus, input[custom-file-input]:focus, .uneditable-input:focus {
border-color: $custom-orange;
box-shadow: 0 1px 1px rgba(229, 103, 23, 0.075) inset, 0 0 8px $custom-orange;
outline: 0 none;
}
As I have seen in many examples. I'd prefer to do it in the style sheet I've made and not go into the actual bootstrap docs.
A good example of what I want comes straight from the Bootstrap website. How do they make the searchbox highlight in purple?
Edit:
It looks like a few changes gets me closer to the result I want.
JSX:
<Form className='file-form col-12'>
<input type='file' className='custom-file-input' id='batch-file'
onChange={e => this.setState({file: e.target.files[0], fileName: e.target.files[0].name})}/>
<label className='custom-file-label' htmlFor='customFile'>{this.state.fileName}</label>
</Form>
SCSS:
.file-form:focus, .file-form:active, .file-form:hover{
border-color: $custom-orange;
box-shadow: 0 1px 1px rgba(229, 103, 23, 0.6) inset, 0 0 8px $custom-orange;
//outline: 0 none;
}
It works almost. There is still a blue glow once i click it.
.form-control:focus {
box-shadow: none;
}
add this

CSS custom style not taking effect

I have the following HTML
<label class="item formulario item-input item-floating-label" ng-class="{'has-error': registroForm.nombre.$invalid && registroForm.nombre.$dirty, 'valid-lr': registroForm.nombre.$valid && registroForm.nombre.$dirty}">
<span class="input-label">Nombre</span>
<input type="text" placeholder="Nombre" name="nombre" ng-model="vm.nombre"
pattern="[A-Za-z'áéíóú ]+"
ng-minlength="2"
ng-maxlength="30"
required>
</label>
I need to set the following style:
label.item.formulario {
border-style: none none solid none;
border-color: darkblue;
}
But the custom style is not taking effect. If I remove my custom name ".formulario" from my CSS selector and also from the class list in my HTML, the style works perfect BUT it modifies the wholes label with an item class. I just need to modify a specific label, this is the reason what I'm trying to create a custom class.
What's wrong?
Thanks for helping!
I've just tested it here and the style does take effect :
https://jsfiddle.net/8eo8crz1/
label.item.formulario {
border-style: none none solid none;
border-color: darkblue;
}
If you want to have a unique custom style for each label, you'll need to use an id instead of a class (or in addition to the classes you're using).

How to change CSS when it's ng-disabled?

I have this button:
<input type="submit" value="#Translator.Translate("PAYOUT")"
class="btn-block secondary-button save-changes padding-8"
ng-disabled="PayoutEnabled==false" ng-click="PayOut()" />
But even when it's disabled it has the same class as it's enabled, just not clickable. I want to change background when it's disabled so that user can see that button, is disabled. How can I do that? Do I need some ng-disabled CSS class or there is some other way?
What Toress answered should work fine but you don't need the help of AngularJS here at all (a native implementation & usage is always best).
You can make use of CSS3 since you already have a class on it. Example:
input.save-changes {
/* some style when the element is active */
}
input.save-changes[disabled] {
/* styles when the element is disabled */
background-color: #ddd;
}
Edit: You can immediately test it on this page of StackOverflow. Just inspect the blue button element and put the disabled attribute and see it's CSS.
.save-changes {
background-color: red;
padding: 7px 13px;
color: white;
border: 1px solid red;
font-weight: bold;
}
.save-changes[disabled] {
background-color: #FF85A1
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app ng-init="PayoutEnabled = true">
<a href="#" ng-click="PayoutEnabled = !PayoutEnabled">
{{PayoutEnabled ? 'Disable' : 'Enable'}} the below button</a>
<br>
<br>
<input class="save-changes" type="submit" value="PAYOUT" ng-disabled="PayoutEnabled == false" />
</div>
use ng-class
<input type="submit" value="#Translator.Translate("PAYOUT")" class="btn-block
secondary-button save-changes padding-8" ng-disabled="PayoutEnabled==false"
ng-click="PayOut()" ng-class="{'diabled-class': !PayoutEnabled}" />
this will add css class diabled-class to the input when PayoutEnabled is false (!PayoutEnabled is true).
AngularJS adds pseudo-class disabled when ng-disabled is false so i think here is the simplest solution to refer to disabled button :
button:disabled {
color:#717782;
}
In case you are using Bootstrap and a more recent Angular version than AngularJs you can ovverride the default style adding this to the styles.css file
.btn.disabled, .btn:disabled {
opacity: .35 !important;
background-color: gray !important;
}
The higher the opacity the darker or more solid the color will be.

Resources