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

Port fixes5 #5713

Merged
merged 32 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
16be84c
Fix #5485: Messages restore close animation
melloware Jan 9, 2024
5860966
Fix #5490: useDebounce fixed
melloware Jan 9, 2024
b582d7c
Fix #5492: Listbox passthrough fixes
melloware Jan 9, 2024
fe5b833
Fix #5493: Multiselect passthrough fixes
melloware Jan 9, 2024
708dd87
Fix #5485: Messages restore close animation
melloware Jan 9, 2024
08e3d94
Fix #5499: Autocomplete/Chips PT fixes
melloware Jan 9, 2024
15fa530
Fix #5479: CascadeSelect PT fixes
melloware Jan 9, 2024
b52cc48
Fix #5509: Button loadingIcon Tailwind fix
melloware Jan 9, 2024
c55eb3f
Fix #5512: Dropdown add tabindex for Tailwind
melloware Jan 9, 2024
3163774
Support roundingMode for InputNumber
melloware Jan 9, 2024
26de1a6
Fix #5523: BlockUI return activeElement focus
melloware Jan 9, 2024
892fe66
Fix #5530: Chip onRemove event pass value
melloware Jan 9, 2024
5662161
DataTable:converted to data- lookups instead of className lookups
melloware Jan 9, 2024
574ea88
Fix #5543: OverlayPanel Tailwind close icon
melloware Jan 9, 2024
9d85802
Fix #5546: prop type error in console
melloware Jan 9, 2024
60fe613
Fix #5555: BodyCell frozen issue
melloware Jan 9, 2024
c6f3d95
Fix #5561: Inplace respect active prop
melloware Jan 9, 2024
f18f017
Fix #5568: MultiSelect filterInput PT
melloware Jan 9, 2024
d9dffea
Fix #5572: Multselect selectAllLabel was being added to DOM
melloware Jan 9, 2024
b09db92
Tooltip fix Tailwind CSS
melloware Jan 9, 2024
f9d14cb
Dialog Breakpoints
melloware Jan 9, 2024
185fac9
Calendar disabled date handling
melloware Jan 9, 2024
8f174ee
Fix #5609: ToggleButton focusedState
melloware Jan 9, 2024
5c5ebb1
Fix #5610: Radio/Checkbox always fire onClick
melloware Jan 9, 2024
33fbffa
fix: #5613, TreeSelect: TreeSelect component is not supporting toolti…
melloware Jan 9, 2024
e4e8f49
Fix #5623 - Otherprops not working for InputSwitch
melloware Jan 9, 2024
4f05bc2
fix:Calendar not showing correctly in Table
melloware Jan 9, 2024
16b12ad
fix:Image preview zoom in bug
melloware Jan 9, 2024
482c88c
Fix #5637: Sidebar aria-label close
melloware Jan 9, 2024
800de22
Accept array as PT value
melloware Jan 9, 2024
55dcd28
Datatable breakpoints
melloware Jan 9, 2024
83b2855
fix:ConfirmDialog: acceptButton's pt don't respect button
melloware Jan 9, 2024
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
2 changes: 1 addition & 1 deletion components/lib/accordion/Accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export const Accordion = React.forwardRef((inProps, ref) => {
};

const isSelected = (index) => {
return props.multiple ? activeIndex && activeIndex.some((i) => i === index) : activeIndex === index;
return props.multiple && Array.isArray(activeIndex) ? activeIndex && activeIndex.some((i) => i === index) : activeIndex === index;
};

React.useImperativeHandle(ref, () => ({
Expand Down
5 changes: 3 additions & 2 deletions components/lib/autocomplete/AutoCompletePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export const AutoCompletePanel = React.memo(
const getPTOptions = (item, key) => {
return _ptm(key, {
context: {
selected: props.selectedItem.current === item
selected: props.selectedItem.current === item,
disabled: item.disabled
}
});
};
Expand Down Expand Up @@ -107,7 +108,7 @@ export const AutoCompletePanel = React.memo(
className: cx('item', { suggestion }),
style,
onClick: (e) => props.onItemClick(e, suggestion),
'aria-selected': props.selectedItem === suggestion,
'aria-selected': props.selectedItem.current === suggestion,
'data-p-disabled': suggestion.disabled
},
getPTOptions(suggestion, 'item')
Expand Down
5 changes: 5 additions & 0 deletions components/lib/autocomplete/autocomplete.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ export interface AutoCompleteContext {
* @defaultValue false
*/
selected: boolean;
/**
* Current disabled state of the item as a boolean.
* @defaultValue false
*/
disabled: boolean;
}

/**
Expand Down
14 changes: 9 additions & 5 deletions components/lib/blockui/BlockUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const BlockUI = React.forwardRef((inProps, ref) => {
const [visibleState, setVisibleState] = React.useState(props.blocked);
const elementRef = React.useRef(null);
const maskRef = React.useRef(null);
const activeElementRef = React.useRef(null);

const { ptm, cx, isUnstyled } = BlockUIBase.setMetaData({
props
Expand All @@ -22,13 +23,18 @@ export const BlockUI = React.forwardRef((inProps, ref) => {

const block = () => {
setVisibleState(true);
activeElementRef.current = document.activeElement;
};

const unblock = () => {
const callback = () => {
setVisibleState(false);

props.fullScreen && DomHandler.unblockBodyScroll();
if (props.fullScreen) {
DomHandler.unblockBodyScroll();
activeElementRef.current && activeElementRef.current.focus();
}

props.onUnblocked && props.onUnblocked();
};

Expand All @@ -46,7 +52,7 @@ export const BlockUI = React.forwardRef((inProps, ref) => {
const onPortalMounted = () => {
if (props.fullScreen) {
DomHandler.blockBodyScroll();
document.activeElement.blur();
activeElementRef.current && activeElementRef.current.blur();
}

if (props.autoZIndex) {
Expand All @@ -67,9 +73,7 @@ export const BlockUI = React.forwardRef((inProps, ref) => {
}, [props.blocked]);

useUnmountEffect(() => {
if (props.fullScreen) {
DomHandler.unblockBodyScroll();
}
props.fullScreen && DomHandler.unblockBodyScroll();

ZIndexUtils.clear(maskRef.current);
});
Expand Down
62 changes: 40 additions & 22 deletions components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1839,11 +1839,7 @@ export const Calendar = React.memo(
}
}

if (props.disabledDates || props.enabledDates) {
validDate = !isDateDisabled(day, month, year);
}

if (props.disabledDays && currentView === 'date') {
if (props.disabledDates || props.enabledDates || props.disabledDays) {
validDay = !isDayDisabled(day, month, year);
}

Expand Down Expand Up @@ -1993,27 +1989,46 @@ export const Calendar = React.memo(
return today.getDate() === day && today.getMonth() === month && today.getFullYear() === year;
};

const isDateDisabled = (day, month, year) => {
const isDayDisabled = (day, month, year) => {
if (props.disabledDates) {
return props.disabledDates.some((d) => d.getFullYear() === year && d.getMonth() === month && d.getDate() === day);
if (props.disabledDates.some((d) => d.getFullYear() === year && d.getMonth() === month && d.getDate() === day)) {
return true;
}
} else if (props.enabledDates) {
if (!props.enabledDates.some((d) => d.getFullYear() === year && d.getMonth() === month && d.getDate() === day)) {
return true;
}
}

if (props.enabledDates) {
return !props.enabledDates.some((d) => d.getFullYear() === year && d.getMonth() === month && d.getDate() === day);
if (props.disabledDays && currentView === 'date') {
let weekday = new Date(year, month, day);
let weekdayNumber = weekday.getDay();

if (props.disabledDays.indexOf(weekdayNumber) !== -1) {
return true;
}
}

return false;
};

const isDayDisabled = (day, month, year) => {
if (props.disabledDays) {
let weekday = new Date(year, month, day);
let weekdayNumber = weekday.getDay();
const isMonthYearDisabled = (month, year) => {
const daysCountInAllMonth = month === -1 ? new Array(12).fill(0).map((_, i) => getDaysCountInMonth(i, year)) : [getDaysCountInMonth(month, year)];

for (let i = 0; i < daysCountInAllMonth.length; i++) {
const monthDays = daysCountInAllMonth[i];
const _month = month === -1 ? i : month;

for (let day = 1; day <= monthDays; day++) {
let isDateSelectable = isSelectable(day, _month, year);

return props.disabledDays.indexOf(weekdayNumber) !== -1;
if (isDateSelectable) {
return false;
}
}
}

return false;
return true;
};

const updateInputfield = (value) => {
Expand Down Expand Up @@ -2582,7 +2597,10 @@ export const Calendar = React.memo(

useUpdateEffect(() => {
if (overlayVisibleState || props.visible) {
alignOverlay();
// Github #5529
setTimeout(() => {
alignOverlay();
});
}
}, [currentView, overlayVisibleState, props.visible]);

Expand Down Expand Up @@ -3654,18 +3672,18 @@ export const Calendar = React.memo(
{monthPickerValues().map((m, i) => {
const monthProps = mergeProps(
{
className: cx('month', { isMonthSelected, isSelectable, i, currentYear }),
className: cx('month', { isMonthSelected, isMonthYearDisabled, i, currentYear }),
onClick: (event) => onMonthSelect(event, i),
onKeyDown: (event) => onMonthCellKeydown(event, i),
'data-p-disabled': !m.selectable,
'data-p-disabled': isMonthYearDisabled(i, currentYear),
'data-p-highlight': isMonthSelected(i)
},
ptm('month', {
context: {
month: m,
monthIndex: i,
selected: isMonthSelected(i),
disabled: !m.selectable
disabled: isMonthYearDisabled(i, currentYear)
}
})
);
Expand Down Expand Up @@ -3697,17 +3715,17 @@ export const Calendar = React.memo(
{yearPickerValues().map((y, i) => {
const yearProps = mergeProps(
{
className: cx('year', { isYearSelected, isSelectable, y }),
className: cx('year', { isYearSelected, isMonthYearDisabled, y }),
onClick: (event) => onYearSelect(event, y),
'data-p-highlight': isYearSelected(y),
'data-p-disabled': !isSelectable(0, -1, y)
'data-p-disabled': isMonthYearDisabled(-1, y)
},
ptm('year', {
context: {
year: y,
yearIndex: i,
selected: isYearSelected(i),
disabled: !y.selectable
disabled: isMonthYearDisabled(-1, y)
}
})
);
Expand Down
93 changes: 93 additions & 0 deletions components/lib/calendar/Calendar.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import { PrimeReactProvider } from '../api/Api';
import { Calendar } from './Calendar';

describe('Calendar', () => {
function getAllDatesOfYear(year) {
let startDate = new Date(year, 0, 1);
let endDate = new Date(year, 11, 31);

let dates = [];
let currentDate = startDate;

while (currentDate <= endDate) {
dates.push(new Date(currentDate));
currentDate.setDate(currentDate.getDate() + 1);
}

return dates;
}

test('When the days of the year are disabled, then the years and month should be disabled', async () => {
const { container } = render(
<PrimeReactProvider>
<Calendar value={new Date(2023, 11, 15)} inline view="year" disabledDates={getAllDatesOfYear(2023)} />
</PrimeReactProvider>
);

const years = container.querySelectorAll('.p-yearpicker-year');

for (const year of years) {
if (year.innerHTML === '2023') {
expect(year).toHaveAttribute('data-p-disabled', 'true');
expect(year).toHaveClass('p-disabled');
} else {
expect(year).toHaveAttribute('data-p-disabled', 'false');
expect(year).not.toHaveClass('p-disabled');
}
}

const { container: monthContainer } = render(
<PrimeReactProvider>
<Calendar value={new Date(2023, 11, 15)} inline view="month" disabledDates={getAllDatesOfYear(2023)} />
</PrimeReactProvider>
);

const months = monthContainer.querySelectorAll('.p-monthpicker-month');

for (const month of months) {
expect(month).toHaveAttribute('data-p-disabled', 'true');
expect(month).toHaveClass('p-disabled');
}
});

test('If any day of the month is not disabled, then both the year and month can be selected', async () => {
const disabledDates = getAllDatesOfYear(2023);

// January and December are not disabled.
disabledDates.shift();
disabledDates.pop();

const { container: yearContainer } = render(
<PrimeReactProvider>
<Calendar value={new Date(2023, 11, 15)} inline view="year" disabledDates={disabledDates} />
</PrimeReactProvider>
);
const years = yearContainer.querySelectorAll('.p-yearpicker-year');

for (const year of years) {
expect(year).toHaveAttribute('data-p-disabled', 'false');
expect(year).not.toHaveClass('p-disabled');
}

// month
const { container: monthContainer } = render(
<PrimeReactProvider>
<Calendar value={new Date(2023, 11, 15)} inline view="month" disabledDates={disabledDates} />
</PrimeReactProvider>
);

const months = monthContainer.querySelectorAll('.p-monthpicker-month');

Array.from(months).forEach((month, index) => {
if (index === 0 || index === 11) {
expect(month).toHaveAttribute('data-p-disabled', 'false');
expect(month).not.toHaveClass('p-disabled');
} else {
expect(month).toHaveAttribute('data-p-disabled', 'true');
expect(month).toHaveClass('p-disabled');
}
});
});
});
4 changes: 2 additions & 2 deletions components/lib/calendar/CalendarBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ const classes = {
clearButton: 'p-button-text',
footer: 'p-datepicker-footer',
yearPicker: 'p-yearpicker',
year: ({ isYearSelected, isSelectable, y }) => classNames('p-yearpicker-year', { 'p-highlight': isYearSelected(y), 'p-disabled': !isSelectable(0, -1, y) }),
year: ({ isYearSelected, y, isMonthYearDisabled }) => classNames('p-yearpicker-year', { 'p-highlight': isYearSelected(y), 'p-disabled': isMonthYearDisabled(-1, y) }),
monthPicker: 'p-monthpicker',
month: ({ isMonthSelected, isSelectable, i, currentYear }) => classNames('p-monthpicker-month', { 'p-highlight': isMonthSelected(i), 'p-disabled': !isSelectable(0, i, currentYear) }),
month: ({ isMonthSelected, isMonthYearDisabled, i, currentYear }) => classNames('p-monthpicker-month', { 'p-highlight': isMonthSelected(i), 'p-disabled': isMonthYearDisabled(i, currentYear) }),
hourPicker: 'p-hour-picker',
secondPicker: 'p-second-picker',
minutePicker: 'p-minute-picker',
Expand Down
9 changes: 7 additions & 2 deletions components/lib/cascadeselect/CascadeSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ export const CascadeSelect = React.memo(
focused: focusedState,
overlayVisible: overlayVisibleState,
attributeSelector: attributeSelectorState
},
context: {
...context
}
});

useHandleStyle(CascadeSelectBase.css.styles, isUnstyled, { name: 'cascadeselect' });
useOnEscapeKey(overlayRef, overlayVisibleState, () => hide());

const elementRef = React.useRef(null);
const overlayRef = React.useRef(null);
const inputRef = React.useRef(null);
Expand All @@ -46,6 +49,8 @@ export const CascadeSelect = React.memo(
when: overlayVisibleState
});

useOnEscapeKey(overlayRef, overlayVisibleState, () => hide());

const onOptionSelect = (event) => {
if (props.onChange) {
props.onChange({
Expand Down Expand Up @@ -330,7 +335,7 @@ export const CascadeSelect = React.memo(
ref: labelRef,
className: cx('label', { label })
},
ptm('label')
ptm('label', { context: { label, ...context } })
);

return <span {...labelProps}>{label}</span>;
Expand Down
6 changes: 3 additions & 3 deletions components/lib/cascadeselect/CascadeSelectBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ const classes = {
'p-ripple-disabled': (context && context.ripple === false) || PrimeReact.ripple === false
}),
sublist: 'p-cascadeselect-panel p-cascadeselect-items p-cascadeselect-sublist',
item: ({ option, isOptionGroup, activeOptionState }) =>
item: ({ option, isGroup, isSelected }) =>
classNames('p-cascadeselect-item', {
'p-cascadeselect-item-group': isOptionGroup(option),
'p-cascadeselect-item-active p-highlight': activeOptionState === option
'p-cascadeselect-item-group': isGroup,
'p-cascadeselect-item-active p-highlight': isSelected
}),
dropdownIcon: 'p-cascadeselect-trigger-icon',
loadingIcon: 'p-cascadeselect-trigger-icon',
Expand Down
Loading
Loading