Skip to content

Commit

Permalink
Fix #5479: CascadeSelect PT fixes (#5507)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Dec 4, 2023
1 parent c3c3ad5 commit f1b9062
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 29 deletions.
17 changes: 8 additions & 9 deletions components/doc/cascadeselect/theming/tailwinddoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,24 @@ const Tailwind = {
label: {
className: classNames('block whitespace-nowrap overflow-hidden flex flex-1 w-1 text-overflow-ellipsis cursor-pointer', 'bg-transparent border-0 p-3 text-gray-700 dark:text-white/80', 'appearance-none rounded-md')
},
dropdownbutton: {
dropdownButton: {
className: classNames('flex items-center justify-center shrink-0', 'bg-transparent text-gray-600 dark:text-white/80 w-[3rem] rounded-tr-6 rounded-br-6')
},
panel: 'absolute py-3 bg-white dark:bg-gray-900 border-0 shadow-md',
list: 'm-0 sm:p-0 list-none',
sublist: {
className: classNames('block absolute left-full top-0', 'min-w-full z-10', 'py-3 bg-white dark:bg-gray-900 border-0 shadow-md')
},
item: {
className: classNames(
'cursor-pointer font-normal whitespace-nowrap',
'm-0 border-0 bg-transparent transition-shadow rounded-none',
'text-gray-700 dark:text-white/80 hover:text-gray-700 dark:hover:text-white/80 hover:bg-gray-200 dark:hover:bg-gray-800/80'
)
},
item: ({ state }) => ({
className: classNames('cursor-pointer font-normal whitespace-nowrap', 'm-0 border-0 bg-transparent transition-shadow rounded-none', {
'text-gray-700 hover:text-gray-700 hover:bg-gray-200 dark:text-white/80 dark:hover:text-white/80 dark:hover:bg-gray-800/80': !state.selected,
'bg-blue-50 text-blue-700 dark:bg-blue-300 dark:text-white/80': state.selected
})
}),
content: {
className: classNames('flex items-center overflow-hidden relative', 'py-3 px-5')
},
groupicon: 'ml-auto',
optionGroupIcon: 'ml-auto',
transition: TRANSITIONS.overlay
}
}
Expand Down
5 changes: 4 additions & 1 deletion components/lib/cascadeselect/CascadeSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export const CascadeSelect = React.memo(
focused: focusedState,
overlayVisible: overlayVisibleState,
attributeSelector: attributeSelectorState
},
context: {
...context
}
});

Expand Down Expand Up @@ -338,7 +341,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',
dropdownButton: 'p-cascadeselect-trigger',
Expand Down
15 changes: 9 additions & 6 deletions components/lib/cascadeselect/CascadeSelectSub.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ export const CascadeSelectSub = React.memo((props) => {
const context = React.useContext(PrimeReactContext);
const { ptm, cx } = props;

const getPTOptions = (key) => {
const getPTOptions = (key, options) => {
return ptm(key, {
hostName: props.hostName
hostName: props.hostName,
state: { ...options }
});
};

Expand Down Expand Up @@ -238,15 +239,17 @@ export const CascadeSelectSub = React.memo((props) => {
getPTOptions('content')
);

const isSelected = activeOptionState === option;
const isGroup = isOptionGroup(option);
const itemProps = mergeProps(
{
className: classNames(option.className, cx('item', { option, isOptionGroup, activeOptionState })),
className: classNames(option.className, cx('item', { option, isGroup, isSelected })),
style: option.style,
role: 'none',
'data-p-item-group': isOptionGroup(option),
'data-p-highlight': activeOptionState === option
'data-p-item-group': isGroup,
'data-p-highlight': isSelected
},
getPTOptions('item')
getPTOptions('item', { selected: isSelected, group: isGroup })
);

return (
Expand Down
26 changes: 23 additions & 3 deletions components/lib/cascadeselect/cascadeselect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
import * as React from 'react';
import { CSSTransitionProps as ReactCSSTransitionProps } from 'react-transition-group/CSSTransition';
import { APIOptions } from '../api/api';
import { ComponentHooks } from '../componentbase/componentbase';
import { CSSTransitionProps } from '../csstransition';
import { PassThroughOptions } from '../passthrough';
Expand All @@ -24,6 +25,7 @@ export declare type CascadeSelectPassThroughTransitionType = ReactCSSTransitionP
export interface CascadeSelectPassThroughMethodOptions {
props: CascadeSelectProps;
state: CascadeSelectState;
context: CascadeSelectContext;
}

/**
Expand All @@ -34,16 +36,34 @@ export interface CascadeSelectState {
* Current focused state as a boolean.
* @defaultValue false
*/
focused: boolean;
focused?: boolean;
/**
* Current overlay visible state as a boolean.
* @defaultValue false
*/
overlayVisible: boolean;
overlayVisible?: boolean;
/**
* Current overlay attributeSelector state as a string.
*/
attributeSelector: string;
attributeSelector?: string;
/**
* For items, this is the state of the item.
*/
selected?: boolean;
/**
* For items, this is whether it is a group item or not.
*/
grouped?: boolean;
}

/**
* Defines current inline context in CascadeSelect component.
*/
export interface CascadeSelectContext extends APIOptions {
/**
* Label of the currently selected item
*/
label?: string;
}

/**
Expand Down
13 changes: 6 additions & 7 deletions components/lib/passthrough/tailwind/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -845,13 +845,12 @@ const Tailwind = {
sublist: {
className: classNames('block absolute left-full top-0', 'min-w-full z-10', 'py-3 bg-white dark:bg-gray-900 border-0 shadow-md')
},
item: {
className: classNames(
'cursor-pointer font-normal whitespace-nowrap',
'm-0 border-0 bg-transparent transition-shadow rounded-none',
'text-gray-700 dark:text-white/80 hover:text-gray-700 dark:hover:text-white/80 hover:bg-gray-200 dark:hover:bg-gray-800/80'
)
},
item: ({ state }) => ({
className: classNames('cursor-pointer font-normal whitespace-nowrap', 'm-0 border-0 bg-transparent transition-shadow rounded-none', {
'text-gray-700 hover:text-gray-700 hover:bg-gray-200 dark:text-white/80 dark:hover:text-white/80 dark:hover:bg-gray-800/80': !state.selected,
'bg-blue-50 text-blue-700 dark:bg-blue-300 dark:text-white/80': state.selected
})
}),
content: {
className: classNames('flex items-center overflow-hidden relative', 'py-3 px-5')
},
Expand Down

0 comments on commit f1b9062

Please sign in to comment.