Text with property text-overflow:ellipsis; pushing text to the left - html

I am working on a react project and I am creating a note taking application with a simple text editor. I have a simple note component that is just a div element with an h3 inside that has these styles:
note {
border-bottom: 1px solid gray;
width: 100%;
padding: 1rem;
box-sizing: border-box;
}
.note h3 {
overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
}
.note:hover {
cursor: pointer;
}
.note.selected {
background: #c9d4d1;
}
Here is also the React code for the note component:
import { useContext, useEffect } from 'react';
import { NotesContext } from '../../App';
import { ResponsiveContext } from '../containers/AppContainer/AppContainer';
import './Note.css';
const Note = ({ note }) => {
const { selectedNoteId, setSelectedNoteId } = useContext(NotesContext);
const toggleEditorView = useContext(ResponsiveContext);
const handleClick = () => {
setSelectedNoteId(note.id);
toggleEditorView();
console.log(note.id);
}
const calculateStyles = selectedNoteId === note.id ? 'note selected' : 'note';
return (
<div onClick={handleClick}
className={calculateStyles}>
<h3>{note.displayTitle || 'New Note'}</h3>
</div>
)
};
export default Note;
I also have a note list which lists all the notes on the left but posting that code as well would make this post so long, you can go to the github repo to see all the code.
When I try to style the text using the text editor and make it a heading (this happens only when I try to make it a heading, when I try to make the text bold and italic it works fine) the first note's text gets pushed to the left if it is long enough (it only happens on the first note no matter which note you are styling with the text editor) and I don't see any updates through the elements tab on the dev tools the element doesn't flash. It is kind of hard to explain what the problem is so I recorded a video showing the exact problem that I am having.

Related

Set style to mat-dialog-container

Im trying to edit the mat-dialog-container but Im not able to, I tried with :host::ng-deep and also I look for answers of this and I found that I should be ablo to give it style by adding a class, but the style is not changin, here is the code about what I found
for the style.css file
.custom-dialog-container .mat-dialog-container {
overflow-y: hidden !important;
display: flex !important;
background-color: red;
}
For the ts componen
abrirForm(id:number){
const data = id??null
this.ventana.open(ModalInspeccionComponent,{data:data, disableClose:true,maxWidth: '100vw', panelClass: 'custom-dialog-container'}).afterClosed().subscribe(e =>{
if (e) {
console.log(e);
}
})
}
The dialog opens outside of the component, so styles in the component file will not be applied to it. Place your styles for .custom-dialog-container in your root css/scss file, and they should apply to the dialog then.
Here is a minimal example: https://stackblitz.com/edit/angular-ivy-ggzfwu?file=src/styles.css

Overriding inline CSS in next js sass module

I use the Twemoji library to get emoji icons in my Next js App, they appear as <span><img></span> in the final HTML and I can override their default width and height using !important in my globals.scss file:
.customize { //Parent class containers 3 buttons, each one has an emoji element
top: 88%;
right: calc(50vw - (52.2px + 3rem));
button {
span img[style]{
width: 35px !important;
height: 35px !important;
}
}
}
Then I tried to extract it as a [].module.scss file, everything works but the images don't change size whatsoever. Why?
Edit
Here is the component I'm trying to style:
import ThemeButton from '../components/themeCustomizeButton' // a button that renders an emoji
import LanguageSwitcher from '../components/LanguageSwitch' // a button that renders an emoji
import Complex from '../components/ComplexitySwitch' // a button that renders an emoji
import styles from "../styles/local/components/customize.module.scss" // importing .module.scss
function Customizing() {
return(
<section className={styles.customize}>
<ThemeButton />
<LanguageSwitcher />
<Complex />
</section>
)
}
export default Customizing
Just use this code before wherever you are trying to extract
$(document).ready(function () {
// Set the size of the rendered Emojis
// This can be set to 16x16, 36x36, or 72x72
twemoji.size = '36x36';
});

Couldn't use the same classname across components. CSS is not being scoped inside a style component

The problem I am having seems to defeat the very purpose of CSS in JS. I am using styled-compomnents. And when I tried to use a classname that is being used somewhere up in the react tree inside a styled component. The upper component classname styles somehow get applied to the classname I used down (very) the tree.
Steps to reproduce
Render UpperComponent anywhere in a react project.
const StyledContainer = styled.div`
.title {
color: red;
margin-bottom: 32px;
}
`;
const UpperComponent = () => {
return (
<StyledContainer>
<FirstComponent />
<h4 className="title"> text inside upper component </h4>
</StyledContainer>
);
};
const FirstStyledContainer = styled.div``;
const FirstComponent = () => {
return (
<FirstStyledContainer>
<h4 className="title">text inside first component</h4>
<SecondComponent />
</FirstStyledContainer>
);
};
const SecondComponent = () => {
return (
<div>
<h4 className="title">text inside second component</h4>
<ThirdComponent />
</div>
);
};
const ThirdComponent = () => {
return (
<div>
<h4 className="title">text inside second component </h4>
</div>
);
};
Expected Behavior
title classname in the UpperComponent should not affect it's descendants' elements with the same classname. It should be scoped only to <h4 className="title"> text inside upper component </h4>
Actual Behavior
.title { color: red; margin-bottom: 32px; } class styles get applied to all the components inside UpperComponent. title somehow makes it down to ThirdCompoent which is nested inide two components.
Is this expected behavior or am I missing something basic (best practice)?
If you want enforce the scoping - You can remove the class names and/or let "styled component" name them (generates a random hash class name) by creating a TitleStyle and attach to the title div (class name "title" can be removed). This should scope to that title only then. Right ?
Another alternative
Yes the FirstComponent and SecondComponent (etc) will catch the css rule from the top. This is the expected result for me. Its not like when we do this below !
<div style = {{color:"red"}}>Test</div>
This would apply the css inline to that div only.
I would slightly change the names of the title classes like so
const StyledContainer = styled.div`
.title {
color: red;
margin-bottom: 32px;
&.secondary { color: pink; }
&.thirdly { color: yellow; }
}
`;
const UpperComponent = () => {
return (
<StyledContainer>
<FirstComponent />
<h4 className="title"> text inside upper component </h4>
</StyledContainer>
);
};
const SecondComponent = () => {
return (
<div>
<h4 className="title secondary">text inside second component</h4>
<ThirdComponent />
</div>
);
};
const ThirdComponent = () => {
return (
<div>
<h4 className="title thirdly">text inside second component </h4>
</div>
);
};
The & is a SCSS operator and works fine with styled components.
CSS is more benifical to behave this way as passing css rules down is more effecient. Work with this effeciency ! You want to create site wide CSS patterns, try avoid specific targeting unless your sure its required (Which should be not too common).
What I do moslty is, created a styled component for the react component, so one per react components to handle all css/scss in that react component.
Daniel
This is working as it should. You're selecting all the .titles in that styled-component.
In the end, styled-components just generate a unique class name for every styled-component you made. So the rules of CSS still work there.
You can
You can select only the direct descendant .title.
const StyledContainer = styled.div`
>.title {
// rules...
}
`
Change the class name to something more specific.
Nest the CSS rule on the parent. So instead of this,
const StyledContainer = styled.div`
.title {
// rules...
}
`
Wrap your h4 with another element and do this
const StyledContainer = styled.div`
.wrapperClassName {
.title {
// rules...
}
}
`

Kendo UI for Angular Grid Detail expand/collapse button to be moved to the right?

Is it possible for the Kendo UI for Angular Grid Detail expand/collapse button to be moved to the right of the grid?
It appears that kendo-ui defaults the expand/collapse to the left most column of the kendo grid. I need to see if it is possible to move it to the button to the right.
We can implement it by hiding the current +/- icons using some custom CSS and manually adding such icons to the last column. Then we would need to programmatically expand and collapse the detail template, when clicking the icons in the last column, by using the expandRow and collapseRow functions of the grid.
Combine these plunkers to see
https://plnkr.co/edit/hc8eYXNTZyFqfRvOiCrc?p=preview
.k-icon.k-plus:before {
content: none;
}
.k-icon.k-minus:before {
content: none;
}
.k-icon.k-plus, .k-icon.k-minus{
pointer-events: none;
}
.k-detail-cell{
overflow: visible !important
}
.k-detail-cell section{
margin-left: -32px;
}
https://plnkr.co/edit/HaCEdMYUtAj4RlpebQnj?p=preview
//import components
import {
GridComponent,
GridDataResult,
DataStateChangeEvent
} from '#progress/kendo-angular-grid';
//get the child
#ViewChild(GridComponent) grid: GridComponent;
//modify your logic here
public ngAfterViewInit(): void {
// Expand all first rows initially
for(let i = 0; i < this.pageSize; i++) {
this.grid.expandRow(i);
}
}

material-ui table: how to make style changes to table elements

I'm using 'material-ui' and trying to get a table element to change color when the element has a certain value. Below is the code I tried, if the cell value is "Out of Zone", the background should go red'ish. The table renders fine, but toggling the color change doesn't work, how come (or is my approach all wrong)?
function renderRowColumn(row, column) {
if (row.status == "Out of Zone") {
return (
<TableRowColumn className="ae-zone">
{row[column.name]}
</TableRowColumn>
)
}
return (
<TableRowColumn>
{row[column.name]}
</TableRowColumn>
)
}
In style.css:
.ae-zone {
background-color: '#e57373';
font: "white";
}
Your specificity on the css selector is not high enough. The rendered TD element has an inline style in which the background property is getting inherited which is overriding your class style.
Is there any reason since you already have the logic seperated out you don't just use inline styles for something like this.
<TableRowColumn style={{backgroundColor:'red', color: 'white',}}>{row[column.name]}</TableRowColumn>
This is definitely working well and I tested it.
Your other option would be to add !important to your css.
td.ae-zone {
background-color: '#e57373' !important;
color: "white" !important;
}
I think if I had to chose though I would recommend the first as it is cleaner.
Don't put quotes around color values in css:
.ae-zone {
background-color: #e57373;
color: white;
}
Also, it's color: white, not font: white.
Most of the time the Table takes the default style, so if the styles didn't get applied try appending !important to the style. This worked for me.
.ae-zone {
background-color: '#e57373' !important;
color:red;
}
There is another way to do this :
import { makeStyles } from "#mui/styles";
// Declare this bellow your import
const UseStyles = makeStyles({
root: {
"& .MuiTableBody-root": {
backgroundColor: "#121212",
},
},
});
// Declare this after your declaration page
const classes = UseStyles();
// Now in your Table, use the class :
<Table className={classes.root}>
<TableHead>
{...}
</TableHead>
</Table>
With the inspector you can see each automatic class from Material UI and target them in the makeStyle.
Be carefull to use the same code example :
"& .MuiClassNameYouWantTarget" : {
textAlign: "center",
},