Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed container overflow #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ li {
border: 1px solid rgba(0, 0, 0, 0.2);
border-radius: 5px;
box-shadow: inset 1px 1px 0 white;
max-height: 450px;
max-height: 500px;
}

#facultyInfo {
Expand All @@ -84,7 +84,7 @@ ul {
margin: 0 auto;
padding: 0;
max-height: 390px;
overflow-y: auto;
overflow-y: scroll;
border: 1px solid rgba(0, 0, 0, 0.1);
padding: 5px 5px 0 5px;
border-left: none;
Expand Down
134 changes: 72 additions & 62 deletions src/myFaculty.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,81 @@ import './App.css';
import facultiesInfo from './data/faculties';
import Profile from './Profile';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faSearch } from "@fortawesome/free-solid-svg-icons";
import { faSearch } from '@fortawesome/free-solid-svg-icons';

export default class AutoCompletedText extends React.Component{
export default class AutoCompletedText extends React.Component {
constructor(props) {
super(props);
this.state = {
suggestions: [],
text: '',
showProfile: false,
selectedFaculty: {},
};
}

constructor(props){
super(props)
this.state = {
suggestions: [],
text: '',
showProfile: false,
selectedFaculty: {}
}
}
onTextChange = (e) => {
const value = e.target.value;
let suggestions = [];
if (value.length > 0) {
const regex = new RegExp(`^${value}`, 'i');
suggestions = facultiesInfo.sort().filter((v) => regex.test(v.FACULTY));
// suggestions = suggestions.map((value) => value.FACULTY);
}

onTextChange = (e) => {
const value = e.target.value;
let suggestions = [];
if(value.length > 0){
const regex = new RegExp(`^${value}`, 'i');
suggestions = facultiesInfo.sort().filter(v => regex.test(v.FACULTY));
// suggestions = suggestions.map((value) => value.FACULTY);
}
this.setState(() => ({
suggestions,
text: value,
showProfile: false,
}));
};

this.setState(() => ({
suggestions,
text: value,
showProfile: false
}))
}
selectedText(value) {
this.setState(() => ({
text: value.FACULTY,
suggestions: [],
showProfile: true,
selectedFaculty: value,
}));
}

selectedText(value) {
this.setState(() => ({
text: value.FACULTY,
suggestions: [],
showProfile: true,
selectedFaculty: value
}));
renderSuggestions = () => {
let { suggestions } = this.state;
if (suggestions.length === 0) {
return null;
}
return (
<ul>
{suggestions.map((item, index) => (
<li key={index} onClick={() => this.selectedText(item)}>
{item.FACULTY}
</li>
))}
</ul>
);
};

}

renderSuggestions = () => {
let { suggestions } = this.state;
if(suggestions.length === 0){
return null;
}
return (
<ul >
{
suggestions.map((item, index) => (<li key={index} onClick={() => this.selectedText(item)}>{item.FACULTY}</li>))
}
</ul>
);
}

render() {
const { text, suggestions } = this.state;
return(
<div id="notebooks">
<h2><FontAwesomeIcon icon={faSearch} /> Search Your Faculty</h2>
<input id="query" type="text" onChange={this.onTextChange} value={text}/>
{this.renderSuggestions()}
{this.state.showProfile ? <Profile {...this.state.selectedFaculty}/> : <div />}
<span>Suggestions: {suggestions.length}</span>
</div>
);
}

}
render() {
const { text, suggestions } = this.state;
return (
<div id='notebooks'>
<h2>
<FontAwesomeIcon icon={faSearch} /> Search Your Faculty
</h2>
<input
id='query'
type='text'
onChange={this.onTextChange}
value={text}
/>
<div>{this.renderSuggestions()}</div>
{this.state.showProfile ? (
<Profile {...this.state.selectedFaculty} />
) : (
<div />
)}
<span>Suggestions: {suggestions.length}</span>
</div>
);
}
}